JSON to Go Struct Converter
Convert JSON objects into strongly-typed Go Struct definitions and data models.
To convert JSON to Go Struct, paste your JSON payload above and specify the root type name. The generator creates clean, idiomatic Go Struct code definitions instantly in your browser without uploading your JSON data to external servers.
Runs in your browser- Privacy
- Runs entirely in your browser — nothing is uploaded
- Cost
- Free, unlimited, no sign-up
From a JSON sample to a Go struct
Each field comes out exported and carrying a json:"..." struct tag holding the original key. Both halves matter. encoding/json ignores unexported fields entirely, so a lowercase field marshals to nothing at all, and without a tag the package falls back to a case-insensitive match on the field name, which holds until a key contains an underscore or a hyphen.
What to fix after pasting
- Optional fields. A
stringthe server omits decodes to an empty string, which is indistinguishable from an empty string that really was sent. Use*stringwhen absent, null and empty are three different things to your code. - Output shaping. Add
,omitemptyto the tag on fields that should disappear from marshalled output when they hold a zero value. - Number widths. Integers infer as
int64and decimals asfloat64. Narrow them when the API documents a range, and use a decimal type or minor units for money rather thanfloat64. - A JSON
nullinfers asinterface{}, which pushes a type assertion into every call site. Replace it with the real type, or a pointer to it. - Arrays are typed from their first element. For a genuinely mixed array,
json.RawMessageis usually a better handle than a slice ofinterface{}, because it defers the decision to a second pass instead of erasing the type.
The same payload in other statically typed backends: JSON to Rust and JSON to C#.
Frequently asked questions
Does this JSON to Go Struct converter upload my files?
How to use the json to go struct converter
- 1Enter or paste your json.
- 2Enter or paste your root type name.
- 3Press Run, then download the result when it is ready.
Sources & specifications
Embed this tool
Put the working json to go struct converter on your own site. It runs in your visitors' browsers exactly as it does here — free, no account, nothing uploaded.
Share this tool
Related tools
Last updated
More data & format tools