JSON to Go
Processed Client SideGenerate idiomatic Go structs with json tags from a JSON sample, with nested types inferred.
Bookmark this tool now — skip the search next time you need it.
About JSON to Go
This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.
Generate idiomatic Go structs from a JSON sample, complete with json struct tags so the result unmarshals correctly without further editing. Field names are converted to exported Go identifiers while the tag preserves the original JSON key, which is exactly the boilerplate that makes hand-writing structs for an unfamiliar API tedious. Nested objects become their own named struct types, arrays become slices of the right element type, and whole numbers map to int while anything with a decimal component maps to float64. Where a value is genuinely ambiguous — an empty array, or a field holding more than one type — it falls back to interface{} rather than guessing wrong.
Key features
- Generates Go structs with json struct tags that preserve the original key names
- Nested objects become their own named struct types
- Arrays become slices with the element type inferred from the contents
- Whole numbers map to int, values with a decimal component map to float64
- Genuinely ambiguous values fall back to interface{} rather than an incorrect concrete type
- Configurable root struct name
- Syntax-highlighted Go output ready to paste into a package
- Parse errors report the offending line in the JSON input
- Runs entirely in your browser — nothing you paste is uploaded
How to use it
- Paste a representative JSON sample into the input pane.
- Set the root struct name to something meaningful.
- Click Convert.
- Copy the generated Go and paste it into your package.
Tips & common mistakes
- Check every int carefully. A field that happens to hold a whole number in your sample may hold a decimal in production, and unmarshalling will then fail at runtime.
- An interface{} in the output marks a spot the sample could not resolve — usually an empty array or a mixed-type field. Those are the fields to pin down by hand.
- Add omitempty to tags for fields that should be left out when empty. The generator emits plain tags, which is the right default but rarely the whole story for request payloads.
- Go zero values hide missing fields: an absent JSON number unmarshals to 0, indistinguishable from a real 0. Use a pointer type where you need to tell those apart.
- Only exported fields — those starting with a capital letter — are unmarshalled by encoding/json. The generator handles this, but it is worth knowing if you rename anything afterwards.
- Dates arrive as strings. Either keep them as string and parse explicitly, or use a custom type with its own UnmarshalJSON.
- Starting from YAML instead of JSON? Generate the same Go structs directly with YAML to Go.