/tools/json-to-go
JSON to Go Struct Generator
Convert JSON into typed Go structs with nested declarations, JSON tags, and evidence-based optional fields.
JSON sample
Go structs
Generate a Go struct for an API response
Generate a root type named Account from:
{"user_id":7,"roles":["reader"]}
The struct contains UserID int64 with a json:"user_id" tag and Roles []string. Use the generated type with json.Unmarshal, checking the returned error. The tag lets the decoder map the original API key onto an exported Go field.
A timestamp string remains a string. Review the generated types against the API contract before adding time parsing or validation.
/usage
How to convert JSON to Go structs
- Paste a representative JSON object or array, drop a file, or load the sample. If needed, check it first in the online JSON Viewer & Formatter.
- Name the root type and Go package, then choose pointer and
omitemptybehaviour. - Generate, review the inferred field semantics, and copy or download the
.gosource.
Generate a Go struct with a JSON tag
Generate from {"user-id":42} to get an exported UserID field tagged with the original JSON key user-id. Review the inferred field types and optional behaviour against representative samples.
/inference
Struct inference across complete JSON samples
Nested objects and arrays
Every object in an array contributes to one merged shape. A field becomes optional only when it is absent from at least one observed object, rather than because the first item happened to omit it.
Idiomatic Go names and tags
Fields are exported, common initialisms such as ID, URL, and API are preserved, name collisions are resolved, and original JSON keys remain in struct tags.
Numbers, null, and mixed values
Whole numbers become int64 and decimals become float64. Nullable concrete values can use pointers; null-only or genuinely mixed values use any with a visible warning.
Bounded local processing
A dedicated worker builds a compact type graph without cloning the parsed payload. Input, traversal, schema, depth, and output limits prevent unbounded work and the worker is released after use.
/faq
JSON to Go questions
Is my JSON sent to a server?
No. Parsing, schema inference, and Go emission run inside your browser. Data Demon does not receive the input or generated code.
Will the generated Go compile without review?
The output is syntactically structured Go, but inference cannot know your domain rules. Review nullability, numeric ranges, time formats, validation, and whether any should become a domain type.
Why does an empty array become []any?
An empty array contains no evidence about its element type. Add a representative item to the JSON sample or replace any after generation.