JSON to Go
This JSON to Go tool generates structs with json tags. Nested objects become properly named sub-structs, and a custom package name and omitempty style options are supported. It runs locally in your browser and the data never leaves your machine.
How to use it
- 1
Paste your JSON
Paste API JSON; nested objects and arrays are expanded into the corresponding Go types.
- 2
Set package and root type
Enter a package name (such as model) and the root struct name; field names are camel-cased automatically.
- 3
Copy the Go code
Structs with `json:"field"` tags are generated, ready to use with encoding/json.
- 4
Wire into your project
Drop the structs into a package and unmarshal the response with json.Unmarshal.
Key features
Standard json tags
Every field gets a `json:"originalKey"` tag, so encoding/json works out of the box.
Exported field names
JSON keys become capitalised camel-case fields (user_id → UserID) to satisfy the Go export rule.
Numeric type inference
Integers default to int64, floats to float64, and nullable or mixed fields fall back to interface{}.
Configurable package
A package name can be supplied, and "Types only" mode keeps the package declaration while omitting parsing boilerplate.
Sub-structs from nesting
Nested objects become named sub-structs rather than anonymous ones, so the code stays readable.
Standard library only
The output depends only on encoding/json, with no third-party packages required.
Common errors & troubleshooting
- ! Go has no optional-field semantics, so nil pointers and zero values need business judgement — review the generated result once.
- ! A time field is a string in JSON and is generated as string; replace it with time.Time by hand and implement custom parsing when needed.
- ! interface{} (writable as any in Go 1.18+) means the field type could not be determined uniquely; more samples help narrow it.
- ! Add omitempty to optional fields in the copied code if that matches your serialisation needs.
Frequently asked questions
Why are some fields interface{}?
The same field appeared with more than one type across samples (for example sometimes a number and sometimes a string). Go is statically typed and cannot express that with one concrete type, so it falls back to interface{} — confirm the type with the API provider and narrow it by hand.
Are omitempty tags supported?
The tool emits standard json tags. omitempty changes zero-value serialisation semantics and is a business decision, so add it to optional fields in the copied code as needed.
Does the generated code need third-party libraries?
No. It depends only on the standard library encoding/json and works with json.Unmarshal / json.Marshal.
Is my JSON uploaded?
No. Generation runs locally in your browser.
Related tools
JSON to Rust
Generate Rust structs from JSON with serde derives. Optional fields are wrapped in Option<T>, and nested objects and Vec<T> are expanded. Runs locally in your browser.
JSON to Java
Generate Java POJOs from JSON with fields, getters/setters and type inference. Choose Jackson, Lombok + Jackson or a plain POJO, and set a custom package name. Runs locally in a Web Worker.
JSON to TypeScript
Generate TypeScript interface or type definitions from a sample JSON payload.
JSON Formatter
Format, beautify and validate JSON in your browser. Errors point to the exact line and column, and you can indent with 2 spaces, 4 spaces or a tab.