JSON to Go Struct
Generate Go struct definitions from JSON data.
Generate Go struct definitions from JSON data.
Related tools
Ready tools are shown first.
Tool guide
Free Online JSON to Go Struct Generator
Generate Go struct definitions from a sample JSON object in your browser. Nested objects become named structs, fields receive exported Go-style names, and JSON tags retain the original property keys.
Steps
How it works
- Paste JSON or choose one JSON or plain-text file.
- Set the root struct name.
- Generate Go field types, nested structs, slices, and JSON tags from the sample.
- Review, copy, or download the Go source.
Highlights
Key features
- Creates named structs for nested JSON objects.
- Converts JSON property names into exported Go field names.
- Adds json tags containing the original keys.
- Infers integers as int, other JSON numbers as float64, booleans as bool, and strings as string.
- Creates slices from the first array item and uses []interface{} for empty arrays.
- Accepts pasted input or one uploaded JSON or text file.
Use cases
Common uses
- Draft Go models for API response examples.
- Create starter structs for configuration payloads.
- Preserve non-Go JSON keys through generated tags.
- Speed up exploratory work with nested JSON objects.
Notes
Limitations to know
- Types are inferred only from values present in the sample.
- Root arrays use the first object; empty arrays, primitive roots, and arrays whose first item is not an object are rejected.
- Arrays use only their first item for element-type inference, so mixed arrays require manual correction.
- Null values become interface{}, and the generator does not add pointers or omitempty tags for optional data.
- Field-name collisions, reserved Go words, and application-specific model requirements require review.
FAQ
Frequently asked questions
Are JSON tags included in the Go structs?
Yes. Generated fields include json tags with the original JSON property names.
How are nested JSON objects handled?
They become named nested struct definitions referenced by the parent field.
Does the generator create pointers for optional fields?
No. It does not infer missing fields, pointers, or omitempty behavior from a single sample.
How are arrays converted?
A non-empty array becomes a slice inferred from its first item; an empty array becomes []interface{}.
What Go types are used for JSON numbers?
Whole sample numbers become int, while sample numbers with a fractional part become float64.