JSON to Go Struct
Convert a JSON sample into a ready-to-use Go struct with json tags. Handles nested structs, slices, unions, and null fields. Runs entirely in your browser.
Input JSON
How it works
- Paste any valid JSON — the struct definition is inferred from the values: numbers, strings, booleans, arrays, and nested objects.
- Whole numbers become
int64, decimals becomefloat64, andnullbecomesinterface. - Arrays of objects become
[]Typeslices; arrays of mixed values become[]interface. - Every field gets a Go field name and a
json:"..."tag matching the original key.
Type mapping rules
| JSON value | Go type |
|---|---|
42 | int64 |
3.14 | float64 |
"hello" | string |
true / false | bool |
null | interface |
[1, 2, 3] | []int64 |
[{...}, {...}] | []Type |
{"a": 1} | struct |
About JSON to Go Struct
Go’s encoding/json needs explicit struct types, and writing them by hand for a large API payload is slow and error-prone. This tool infers the struct skeleton from a representative JSON sample and emits idiomatic fields with json tags, so the decoder maps keys correctly even when Go field names differ. Nested objects become nested structs and arrays of objects become slices of structs.
Inferred output reflects only the sample: fields that are absent from the sample will be missing from the struct, and optional fields that happen to hold null become interface. After generating, review the result, add omitempty where you want zero values skipped, and consider json.RawMessage for polymorphic fields. The tool runs fully locally — paste production payloads safely.