Code generators
JSON to Go Struct Generator
Paste JSON and get gofmt-style structs with correct json tags in seconds. Optional fields detected across array items get omitempty, nullable values become pointers, and ints stay ints.
- Runs 100% in your browser
- No signup · No uploads
- Free, unlimited use
JSON sample
Examples: User object · Webhook event — ⌘/Ctrl + Enter converts · drop a file to load it · processed locally
Go structs
Output is read-only. Use Copy, Download or Share to move it out.
How to use the json to go tool
-
Paste your JSON
A response from the API you are integrating works best. Include several array items so optional fields are visible.
-
Set the root type name
Name it after the resource: User, Event, Order. Nested types are named from their keys automatically.
-
Copy into your Go file
Paste into your project and run gofmt. Field names are capitalised, tags match the original keys exactly, so json.Unmarshal works immediately.
What makes this one different
- json tags faithful to the original keys, including snake_case and dashes
- omitempty for fields missing in some array items
- Pointer types for genuinely nullable values (*string), so null unmarshals cleanly
- int vs float64 from actual sample values; any for irreconcilable mixes
- gofmt-compatible output with tab indentation
Privacy by architecture: this page contains no analytics that receive your input, and the conversion code runs in your tab. You can disconnect from the network after loading and keep working.
JSON to Go — frequently asked questions
Why do some fields become pointers?
A JSON null cannot be stored in a plain string or int, so a nullable field gets a pointer (*string, *int). That lets encoding/json distinguish “absent” and “present but null” without failing, which is exactly what pointer types are for.
What happens when a field has mixed types?
If a value is a string in one item and a number in another, the generator uses any rather than inventing a wrong concrete type. You can then decide on a custom UnmarshalJSON if the API is really that loose.
Do the generated tags include omitempty?
Only for fields that were missing from at least one item in your sample. Required fields get plain tags, so round-tripping does not drop data.
Is the output gofmt-compatible?
Yes — tabs, alignment and field ordering follow gofmt conventions. Run gofmt -l after pasting and it should report no changes.
Can I generate structs for large responses?
Yes. Nested objects become separate named structs while cycling is impossible in parsed JSON, so even deeply nested payloads generate a flat, readable set of types.
Related tools
Searching for “json to golang struct”, “go struct generator”, “json to go online”? You are in the right place — browse all 19 tools.