Advertisement

JSON to Go Struct

Convert JSON into Go structs with json tags. Nested objects become nested structs, arrays become slices, and uncertain fields become pointers.

JSON input

Paste JSON, optionally name the root type, then generate.

Your Go struct code will appear here.
Advertisement

Idiomatic Go from JSON

Go field names use CamelCase while JSON keys are often snake_case, and the generated json tags bridge that gap. The tool infers int, float64, bool, string, slices, and nested structs, marking shaky fields as pointers.

From API response to typed code

Copy a real response from your API logs, generate the structs, and unmarshal directly into them. Compile time field names replace stringly typed map access, and the json tags keep the wire format intact.

JSON to Go Struct FAQs

What are the json tags for?
Tags like `json:"name"` tell Go's encoding/json package which JSON key maps to each field, so you can use idiomatic CamelCase field names while matching snake_case APIs.
How are nested objects handled?
Each nested object becomes its own struct type named after its key, declared above the parent, which is the standard Go pattern for composite API responses.
Why do some fields become pointers?
Fields that are null or missing in some records become pointers like *string, so your code can distinguish an absent value from a zero value.
How are arrays represented?
JSON arrays become Go slices like []string or []Project, which is exactly what json.Unmarshal fills when decoding a list.
Does this work with encoding/json?
Yes. The output uses only the standard library: call json.Unmarshal(data, &myStruct) and the tags handle the key mapping automatically.
Advertisement