JSON to Go Struct — Generate Go Struct Types from JSON
Generate Go struct types from JSON with json tags. CamelCase fields, omitempty for nullable, time.Time detection — in your browser, no upload.
JSON to Go Struct
Convert JSON to Go struct with json tags. Works entirely in your browser.
Go’s standard library ships with one of the most widely used JSON parsers in any language: encoding/json. The parser is fast, correct, and famously opinionated — it expects struct fields to be exported (CamelCase, with a capital first letter), and it resolves the mapping from JSON keys to struct fields through struct tags. Writing Go structs by hand for every API response is the most common chore in Go service development, and it usually starts with a single representative JSON response pasted into a code generator. The generator walks the JSON object, infers Go types for each value, and emits a struct with the correct json tags — a task that takes five minutes by hand and five milliseconds by machine, and the machine doesn’t forget an omitempty on the nullable field.
The non-obvious Go-specific nuance is pointer types. In JSON, a field can be present with a value, present with a null value, or absent. In Go, a zero value (empty string, zero int, false bool) and an absent value are indistinguishable in a plain non-pointer field. The standard library’s solution is omitempty: a field tagged json:"key,omitempty" is omitted from the output when it holds the zero value, and a pointer type (*string with omitempty) is omitted when the pointer is nil but emitted as the zero value when the pointer is non-nil. The generator chooses pointers for nullable fields in the sample and non-pointers for always-present fields — the right default for most APIs, but worth reviewing if your API uses null and absent differently.
For a final hand-off: if the generated struct lands in a Go service, add custom UnmarshalJSON methods for date-parsing, enum validation, or polymorphic dispatch. If the destination is a database, add db tags alongside the json tags for ORM compatibility. The generated struct is the schema — the business logic that reads and writes it is the part that belongs in the developer’s hands.
How to use
Paste your JSON
Drop a JSON object or array of objects into the input. The generator walks the structure and emits a Go struct for the root, with nested structs for each object shape.
Pick naming conventions
Choose between CamelCase fields (idiomatic exported Go) and all-lowercase with json tags. Toggle `omitempty` for nullable values to match the standard library's JSON marshaler.
Copy or download the struct
Copy the Go struct to your clipboard or download as a .go file. The output is paste-compatible with `encoding/json` and `json.Unmarshal` — no extra imports needed.
Frequently asked
Why does a numeric field become float64 instead of int?
JSON numbers are, by specification, not typed as integers or floats. The generator defaults to `float64` for numbers that contain a decimal point and `int` for whole-number values. Add type assertions by hand if the sample data doesn't capture the full range of values your API may return.
How are JSON null values handled?
Fields that are null in the sample become pointers with `omitempty`: `*string `json:"key,omitempty"``. This is idiomatic Go — a nil pointer means absent, a pointer to the zero value means present-but-empty. If you know the field is never absent, remove the pointer and the omitempty tag.
Does it emit struct tags for JSON?
Yes, every field is tagged with `json:"original_key"` or `json:"original_key,omitempty"`. The tag preserves the exact JSON key case, which is important when the source JSON uses snake_case and the Go struct field is CamelCase.
What about embedded objects and arrays?
Nested objects become nested structs with CamelCase names derived from the JSON key. Arrays become `[]Type` slices. Arrays of mixed types become `[]interface{}` — add a type assertion or unmarshal step by hand if the array is heterogeneous.
Will it generate a main function?
No. The output is a type definition only — a struct. Write the `func main()` entry point and the `json.Unmarshal` call yourself. The generator's job is to solve the repetitive type-definition task, not to write a complete Go program.
Limitations
- No custom unmarshal logicThe struct uses the default encoding/json unmarshal behavior. If your JSON uses a custom date format (not RFC 3339), a numeric enum, or a polymorphic type key, you'll need to write a custom UnmarshalJSON method by hand.
- Inferred types from a single sampleA field that is a number in the sample may be a string in another API response. The generator infers the type from the sample — review if your API is inconsistent.
- No generics supportThe output is pre-generics Go (no type parameters). For Go 1.18+ generics, post-process the output to add type constraints or interface constraints by hand.
Platform notes
- macOS
- GoLand, VS Code with the Go extension, and vim-go all accept the generated struct. The browser tool is the right pick for one-off generation from a sample API response pasted from a browser or terminal.
- Windows
- GoLand and VS Code on Windows both handle the generated struct. The browser tool is the right pick for content pasted from a chat, email, or API explorer that needs to land as a Go struct without opening an IDE.
- Linux
- For command-line work, `quicktype --lang go` or `gojson` are the standard equivalents. The browser tool is the right pick for one-off generation where installing a CLI tool is not worth the setup time.
- Web
- Runs entirely client-side. Works offline once the page has loaded. Useful for restricted environments or quick conversions during code review.