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

Type mapping rules

JSON valueGo type
42int64
3.14float64
"hello"string
true / falsebool
nullinterface
[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.