About JSON to Go Struct
Generates Go structs from a JSON sample, entirely in your browser. Nested objects become their own named structs, arrays of objects merge into a single struct, numbers are typed as int or float64 by value, booleans as bool, and null or mixed values as interface{}. Keys that appear in only some elements of an object array become pointer fields with a ,omitempty json tag — the idiomatic Go way to model optional fields. Every field gets an exported name and a json tag preserving the original key, with the output column-aligned like gofmt.
- Nested objects become separate named structs referenced by field type
- Arrays of objects are merged; keys missing from some elements become *T with json:"key,omitempty"
- Numbers infer to int (whole) or float64 (decimal); booleans to bool
- null and mixed arrays become interface{} / []interface{}
- Exported (capitalized) field names with json tags preserving the original key
- Output is column-aligned (gofmt-style); runs fully client-side
Frequently Asked Questions
- Why are some fields pointers with omitempty?
- When a key appears in only some elements of an array of objects, it is optional. In Go the idiomatic way to represent “may be absent” is a pointer (*T) plus json:"key,omitempty", so the field can be nil and is omitted when empty on marshal.
- How are numbers typed?
- By the sample value: whole numbers become int, numbers with a decimal become float64. JSON has a single number type, so if a field is sometimes whole and sometimes decimal in your data, prefer float64 and adjust the generated type.
- Is the output ready to compile?
- Yes — it is valid Go with exported field names, json tags, and gofmt-style alignment. Paste it into a .go file; rename the root struct to taste.
More Development Tools
All Development toolsDocker Compose Validator
Parse Docker Compose YAML and statically check services, dependencies, ports, build/image sources, and obsolete version fields in the browser.
JSON Schema Validator
Validate JSON against a JSON Schema.
Regex Tester
Test regex patterns with live highlighting, named & numbered capture groups, and a replace/substitution preview.
JSON Validator
Check if JSON is valid and find syntax errors.