JSON to Go struct
Paste a JSON sample to get Go structs with json tags: named nested structs, pointers for fields that may be null, omitempty for fields not always there.
How to generate a Go struct from JSON
- Paste a JSON sample on the left or open a .json file; the Go structs appear on the right.
- Rename the root type if you like, for example User or APIResponse.
- Copy it or download the .go file and paste it into your package.
Frequently asked questions
Whole numbers are int, very large ones (such as 19-digit IDs) int64, and numbers with decimals float64. Arrays become slices and nested objects their own structs.
A field that is sometimes null needs a pointer to tell "not there" from an empty value. A field found only in some array items also gets omitempty in its tag.
With a capital first letter so they are exported, as Go requires, and common initialisms in capitals (id → ID, userUrl → UserURL). The json tag keeps the exact JSON name.
When a value is always null, for empty arrays, or when a field holds several kinds of value. Paste a fuller sample or fix the type by hand.
It is completely free and needs no sign-up.
Related tools
JSON to TypeScriptGenerate TypeScript interfaces from sample JSONJSON to JSON SchemaGenerate a JSON Schema from a JSON sampleJSON to Python dataclassGenerate dataclasses or Pydantic models from JSONJSON to Java classGenerate Java classes or records from JSONJSON to Kotlin data classGenerate Kotlin data classes from a JSON sampleJSON Escape / UnescapeTurn text into a valid JSON string and backJSON FormatterFormat, minify and validate JSONJSON RepairAutomatically fix broken JSONJSON CompareFind the differences between two JSON documents