
JSON to Go Struct
Turn a JSON sample into Go struct definitions.
Runs in your browser. Nothing you type is uploaded.
How the converter works
Paste a JSON sample and the Go code appears as you type. Each object becomes a struct, field names are converted to exported Go names (user_id becomes UserID) and every field gets a json tag with the original key, soencoding/json can decode your data straight into it.
How types are chosen
- Whole numbers become
int; numbers with a fraction becomefloat64. A mix of both in an array becomesfloat64. - Strings and booleans become
stringandbool. Anullvalue, an empty array, or a place that holds different types (Go has no union types) becomesany. - Arrays of objects are merged into one struct. Fields missing from some items get
omitempty, and fields that are sometimesnullbecome pointers such as*string. - Nested objects become their own named types, or choose Inline structs to keep them inside the parent.
FAQ
Is the output exactly what I should ship?
It is a good starting point, but a sample cannot tell the whole story. Check optional fields, consider int64 for large IDs, and use time.Time for dates if you want Go to parse them.
Does it work with the Go playground?
Yes. Paste the code under a package main line and import encoding/json to decode into it.
Is my JSON sent anywhere?
No. The conversion runs in your browser, so your data stays on your device.
More JSON tools
- JSON formatter: Format, minify and validate JSON in one place.
- JSON validator: Check JSON syntax and find the exact line and column of an error.
- JSON beautifier: Pretty print JSON with 2 spaces, 4 spaces or tabs.
- JSON minifier: Strip whitespace to make JSON as small as possible.
- JSON to TypeScript: Generate TypeScript interfaces or types from a JSON sample.
- JSON to Python: Generate Pydantic models, dataclasses or TypedDicts from a JSON sample.
- JSON to Rust: Generate Rust structs with serde derives from a JSON sample.