JSON to Go
Generate Go structs with JSON tags from JSON
Paste JSON or load an example to generate Go code.
What JSON to Go generates
JSON to Go turns an API response or any JSON sample into Go struct definitions ready for encoding/json. Every exported field carries a json:"key" tag, so renamed fields still decode. Keys that a struct tag cannot express (empty keys, quotes, commas or symbols such as emoji) are excluded with json:"-" and listed in the notes, instead of silently mapping to the wrong name.
How to use
- 1.Paste JSON, upload or drop a .json file, or load one of the examples.
- 2.Set the root struct name and package (main by default).
- 3.Turn pointers and omitempty on or off; under Advanced you can inline nested structs.
- 4.Read the notes under the output, then copy the code or download models.go.
How types are inferred
- •Every array item is inspected, not just the first one, and objects in the same array are merged.
- •A key missing from some objects is optional; a key that is sometimes null is nullable. The two are kept apart.
- •1 and 2.5 in the same position widen to a decimal number; other mixes are reported.
- •Empty arrays and values that are only ever null have no type evidence, so a generic type is used and a note explains why.
- •Type mapping: string → string, integer → int64 (uint64 or json.Number beyond that), decimal → float64, boolean → bool, array → []T, object → struct, unknown or mixed → any.
- •With pointers on, nullable or optional scalars and structs become *T; slices and any are never pointers because they already have a nil value.
omitempty, limits and privacy
omitempty is added only to fields that were missing or null in the sample. It also drops zero values such as 0, "" and false when encoding, so it is not the same as "optional". A sample shows what the data looked like once, not the full API contract. Review optional fields, generic types and number widths before relying on the code. Input is limited to 5 MB and 256 nesting levels; from 2 MB, generation waits for the Generate button. Everything runs in your browser and the JSON is never uploaded.
