About this tool
Generate production-ready Go structs from JSON with nested objects, arrays, nullable fields, JSON tags, copy, download, and local history.
The JSON to Go Struct Generator turns a pasted JSON payload into compilable Go type declarations, inferring string, bool, int, float64 and interface{} from the actual values and emitting a `json:"..."` tag on every field. Nested objects become their own named structs, arrays of objects are merged so a field that appears in only some elements still gets declared, and you choose whether nullable fields render as pointers (*string) or as interface{}. It is built for Go developers wiring up a client against an API they only have sample responses for.
Open JSON To Go Struct Generator on AltFTool — it loads instantly in your browser.
Paste your payload into the JSON Editor ('Paste valid JSON here...'), or press Upload to load a .json or .txt file, then name the Root struct name and Package name in the Settings box.
Under Null values choose 'Pointer when type is known' for types like *string or 'interface{} fallback', and press Beautify or Minify to reshape the input — the structs regenerate as you type.
Read the Generated Go Preview with its JSON size, Fields, Structs, Depth and Lines tiles, then press Copy, Download for AutoGenerated.go, or Save to keep it under Recent Structs.
Fields are collected across all objects in a JSON array, so optional keys present in only one record still appear in the struct.
Keys are converted to exported PascalCase and known initialisms like ID, URL, API, UUID and HTTP stay fully capitalised.
Switch between pointer types for fields that ever appear as null and a plain interface{} fallback, and see the difference immediately.
A JSON number becomes int only when it is a safe integer with no fractional part; anything else becomes float64. If the same key is an integer in one record and a decimal in another, the two are merged to float64 rather than left ambiguous.
With the pointer setting the field is emitted as a pointer type such as *string so you can tell null apart from the zero value; with the interface setting it becomes interface{}. Slices and interface{} are never given a pointer, since both already carry a nil state.
Yes, as long as the array contains objects. The generator builds one root struct from the union of all object elements; an array of plain strings or numbers has no struct to describe and is rejected with an error.
It is renamed with a Field suffix, so a key named type becomes TypeField while the tag still reads `json:"type"`. Keys starting with a digit get a prefix for the same reason, since Go identifiers cannot begin with a number.
Add the JSON To Go Struct Generator widget to your blog or website — free, responsive, no signup. Just keep the “Widget by AltFTool” credit link visible.
<iframe src="https://www.altftool.com/embed/widget/json-to-go-struct"
title="JSON To Go Struct Generator — free AltFTool widget"
width="100%" height="640" style="border:0;border-radius:12px;overflow:hidden"
loading="lazy" referrerpolicy="no-referrer-when-downgrade" allow="clipboard-write"></iframe>
<p style="font-size:12px;margin:4px 0 0">Widget by <a href="https://www.altftool.com/tools/all/json-to-go-struct?utm_source=embed&utm_medium=widget" rel="nofollow">AltFTool — free online tools</a></p>