JSON to Go
Paste JSON and instantly generate Go structs with json tags in your browser. Free, fast, no signup - ideal for API models and quick prototypes.
Your result will appear here.
JSON to Go online
Generate a Go struct from a JSON sample — PascalCase fields with json tags, types inferred from the values — ready to paste into a Go service that unmarshals the payload.
How to use this tool
- Set the struct name for the root type.
- Paste a representative JSON object into the input box.
- Click Generate and copy the struct into your Go file, then adjust types where the sample was ambiguous.
Common uses
Modelling an API response for encoding/json, turning a config document into a typed struct, exploring an unfamiliar payload's shape, and skipping the hand-typing on client projects.
How it works
The generator infers a Go type per value: text becomes string, whole numbers int, decimals float64, booleans bool, and arrays a slice of the element type. Field names are converted to PascalCase for export, with the original key preserved in a json:"..." tag so unmarshalling matches the wire format. Nested objects become nested structs; values with nothing to infer from — nulls, empty or mixed arrays — fall back to interface{}.
Worked example
With struct name User and the sample
{ "name": "Ana", "age": 30, "score": 9.5, "admin": false }the output is a User struct with Name string, Age int, Score float64 and Admin bool, each carrying its original key as a json tag — directly usable with json.Unmarshal.
Privacy and browser processing
Your JSON is processed in your browser with JavaScript — it is never uploaded or stored.
Frequently asked questions
Why did a field become interface{}?
The sample gave no type evidence: the value was null, or the array was empty or mixed. Paste a sample where that field holds a typical value and regenerate.
Are the json tags correct?
Each field keeps its exact source key in the tag, including keys with underscores or dashes that PascalCase would otherwise lose. Check tags on keys with capitals — Go matches tags literally, and the generator preserves what you pasted.
Should IDs be int?
Only if they are small and truly numeric. JSON numbers beyond int64 range, and IDs that merely look numeric, are safer as json.Number or string — adjust after generating, since inference sees shape, not semantics.
Does it handle arrays of objects?
Yes — the field becomes a slice of a struct inferred from the elements. Give the array at least one complete element in the sample for a full field set.
Is my JSON uploaded?
No. Generation runs in your browser; nothing is sent anywhere.