JSON to Go
Turn one JSON sample into Go structs and json tags.
Added 2026-10-31
What it does
JSON to Go reads one JSON sample and writes exported Go structs with json tags. A nested object becomes its own named struct. Objects inside an array are merged. A field that is missing from some of those objects becomes a pointer, and omitempty is not added, because omitempty also drops 0 and false. null stays a pointer when a sibling shows the type, and a lone null stays any. An empty array becomes a slice of any. An empty object becomes map[string]any. A safe integer becomes int. A fraction becomes float64. An integer past 2^53 - 1 stays int, with a comment that JSON did not keep it exactly. The result describes this sample only. The original key stays in the tag. The JSON is not uploaded.
How to use it
- Paste one JSON value. The root name defaults to Root.
- Read the structs. Nested objects and array objects get names.
- The types describe this sample. They are not a schema for every future value.
Common mistakes
- omitempty is not added. A missing field becomes a pointer. omitempty would also drop 0 and false, so it is left off.
- This is one sample. A field that is absent here is absent in the struct. A later object with more fields needs to be pasted again.
The conversion stays in this tab. The JSON is not uploaded.
Related guides
- A JSON sample is not a schema
A schema generated from one sample describes that sample. Validation checks a document, and remote $ref is not loaded.
- JSON integers past 2^53
Why JSON.parse rounds large integers, and how to keep every digit when you only need to format JSON.