JSON to Go Struct
Generate Go structs with json tags from a JSON object
About JSON to Go Struct
Builds Go structs with json tags from a JSON sample: a Root struct plus one struct per nested object, with keys converted to PascalCase field names. Null values become interface{}, empty arrays []interface{}, and a top-level array also gets a RootList slice type. Fields are separated by single spaces rather than aligned, so run gofmt on the result.
Category: Converters.
Frequently asked questions
What are json struct tags?
▾
Go struct tags (e.g. `json:"name"`) tell the encoding/json package which JSON key maps to each struct field during Marshal and Unmarshal.
How are nested objects handled?
▾
Each nested object becomes its own struct named after its key in PascalCase (address becomes Address), and the parent field uses that type. Arrays are typed from their first element, so an array of objects becomes a slice such as []Items. Objects stored under the same key name share one struct built from the first occurrence, so check it if their shapes differ.
When is float64 vs int used?
▾
If the sample number has no decimal part, the converter outputs int. If it has a fractional part, it outputs float64. Adjust to int64 or float32 as needed.
How do I unmarshal JSON into the struct?
▾
Use json.Unmarshal([]byte(jsonStr), &root) or json.NewDecoder(r.Body).Decode(&root) — the generated struct tags wire everything up automatically.