JSON to Go
Generate Go structs with json tags from a JSON sample, ready for encoding/json.
JSON input
Generated code
Enter JSON on the left to generate a type from it.
What is JSON to Go?
A JSON to Go converter reads a sample JSON document and generates the Go struct definitions needed to decode it with encoding/json. Go's standard library unmarshals into concrete types rather than a generic map, so consuming any new API response means first writing out a struct whose fields match the payload — including a `json:"..."` tag on every field, because Go requires exported (capitalised) field names while JSON keys are usually lowercase or snake_case. Writing those structs by hand is slow and easy to get subtly wrong: one mistyped tag and the field silently stays at its zero value with no error at all, which is among the most common bugs when integrating a new endpoint. This generator produces the whole set at once, giving every nested object its own named struct so the result is ready to paste into a package.
How to use JSON to Go
- Paste a representative JSON response into the left panel — include every optional field you care about, since a field absent from the sample won't appear in the generated struct.
- Set a root type name in the box above the output (defaults to "Root"); nested objects are named after the key that holds them.
- Copy the generated structs into your package and decode with json.Unmarshal or a json.Decoder.
- Need a different language instead? The picker above the output switches the same input to Rust, TypeScript, Python, and five others.
Examples
Flat object with JSON tags
Input
{"id": 1, "name": "Ada", "active": true}
Output
type Root struct { Id int64 `json:"id"` Name string `json:"name"` Active bool `json:"active"` }
Nested object becomes its own struct
Input
{"user": {"id": 1, "name": "Ada", "roles": ["admin"]}}
Output
type User struct { Id int64 `json:"id"` Name string `json:"name"` Roles []string `json:"roles"` } type Root struct { User User `json:"user"` }
Common mistakes
- Editing the Go field name without updating the `json:"..."` tag — encoding/json then finds no matching key, and the field silently stays at its zero value instead of raising an error.
- Using a value type for a field that can be null or missing, which makes an absent field indistinguishable from one legitimately set to 0, false, or the empty string.
- Generating from a sample that omits optional fields — the resulting struct simply won't have them, so those values are dropped on decode without any warning.
Why use this tool
- Emits the `json:"..."` struct tags automatically, which is where hand-written Go structs most often go wrong.
- Gives every nested object its own named, reusable struct instead of burying it in an anonymous inline definition.
- Runs entirely client-side, so real API responses used as samples never leave your browser.