JSON to Go struct generator
About JSON to Go
The JSON to Go converter turns a sample JSON payload into Go structs with `json:"..."` tags that keep your original field names. Fields are exported in PascalCase, types are inferred, and every nested object gets a named struct.
It is the boilerplate you would otherwise write by hand before calling `encoding/json`. Use it for a third-party webhook, a config type or an undocumented endpoint. Runs in your browser. Nothing is uploaded.
How it works
Types inferred from the values
Strings map to `string`, booleans to `bool`, whole numbers to `int64` and decimals to `float64`. Arrays become slices (`[]string`, `[]Item`). Null values and empty array elements become `interface{}`. Field names are PascalCased for export, and the json tag keeps the exact original key.
Named structs for nested objects
Every nested object becomes its own named struct, so a `plan` object turns into a `Plan` struct used by the parent. Objects inside arrays merge into one element struct, so `[]User` covers every element. If two paths would produce the same name, a numeric suffix keeps them apart.
Optional detection across arrays
With Optional detection on (the default), the generator compares every object in an array. A key missing from some elements gets `,omitempty` in its tag and a pointer type like `*string`, so it can be nil. That lets Go code tell an absent field from a zero value.
Inline nested structs toggle
Leave Inline off for named top-level structs, which are easier to reuse across your package. Turn it on to embed each nested object as an anonymous `struct { ... }` inside its parent. Either way, names, types and tags are aligned like gofmt output.
Frequently asked questions
Is it safe to paste production JSON here?
Yes. Struct generation runs in your browser and the JSON is never sent anywhere. The tool also works offline.
Why does it use int64 instead of int?
JSON numbers can exceed a 32-bit int, so int64 is the safe default. Change it to int, int32 or uint if your data guarantees a smaller range.
What does the omitempty and pointer output mean?
With Optional detection on, a field missing from some objects in an array gets ,omitempty in its tag and a pointer type like *string. Your code can then tell an absent field from a zero value, and the field is left out when you marshal back to JSON.
Why did a field become interface{}?
A null, an empty array or a mix of incompatible types cannot map to one Go type, so it falls back to interface{} (the same as `any`). Use a fuller sample to get a precise type.
Should I use named or inline nested structs?
Use named structs (Inline off) when you want to reuse the nested types elsewhere in your package. That is the more common Go style. Use inline structs when you want one self-contained type.
Learn more
Sources & last verified
We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.
Found a wrong result or an outdated claim? Report an error and we will check it again.