JSON to Go
About this tool
Typing structs from a payload misses fields. Paste a real sample and the page splits nested objects into types. Turn on gorm when the struct maps to a table. Inference follows this snapshot only—nulls and mixed shapes still need a pass.
Features
- Infers nested structs and slices from the sample
- Custom root type name
- Optional gorm column tags
How to use
- Paste a real API payload, not a toy object.
- Name the root struct, for example User or Order.
- Enable gorm tags if the type maps to a table.
- Copy the code, then tighten nulls and mixed types by hand.
When to use it
- You have a response and need a Go model today
- Too many nested objects to tag manually
- The struct will land in a database
Examples
- {"user_id":1} becomes UserId with a json tag.
- A root array yields an element struct used in a slice.
FAQ
Are inferred types always right?
They follow the sample. Null fields and numbers-as-strings need a manual pass.
Does a root array work?
Yes. The generator emits the element struct and uses it in a slice.
When should I enable gorm tags?
When the struct maps to a table. Skip them for transport-only DTOs.
How is this different from JSON to TypeScript?
This page emits Go. Use JSON to TypeScript for frontend types. Both infer from one JSON snapshot.
Is the sample uploaded?
No. Generation stays in the browser.
What if the JSON is invalid?
Fix it with the JSON validator or formatter, then convert again.
Back to JSON Tools Hub
Guides