JSON to Go Struct
Convert JSON to Go structs with json tags filled in
What is JSON to Go Struct?
This JSON to Go converter infers struct definitions from sample data: field names become exported CamelCase with matching json tags, integers and floats map to int64 and float64, and nested objects are extracted into their own named types. The inference runs entirely in your browser.
How to use JSON to Go Struct
- 1Paste a representative JSON response.
- 2Enter a name for the root struct.
- 3Copy the generated structs and switch optional fields to pointer types to match your backend contract.
Frequently asked questions
Why are integers inferred as int64 rather than int?+
A single sample says nothing about the real range of a JSON number, and int is only 32 bits wide on 32-bit platforms, so large values such as millisecond timestamps or snowflake IDs would overflow. int64 is the safer default, and you can narrow it once you know the range.
How should optional fields be handled?+
One sample cannot distinguish a missing field from a field holding the zero value. When that difference matters, change the field to a pointer type such as *string and add omitempty to its tag, which cleanly separates nil from the empty string.
Related tools
All toolsJSON to YAML Converter
Convert JSON to YAML while preserving the nesting
YAML to JSON Converter
Convert YAML to JSON, multi-document files included
JSON to CSV Converter
Convert a JSON array of objects to CSV, with nested fields flattened automatically
CSV to JSON Converter
Convert CSV to JSON with automatic header and delimiter handling
JSON to TypeScript
Infer TypeScript type definitions from JSON
JSON to Python Dataclass
Convert JSON to Python dataclasses or Pydantic models