How to convert JSON to Go
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated Go code into your project.
What you get
- One struct per object, with
json:"…"tags that keep the original key names. - Exported field names in Go style, keeping initialisms in capitals:
userIdbecomesUserID. - Pointers plus
omitemptyfor optional fields, andanyfor values of mixed type.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
How do I use the generated structs?
Paste them into your package and decode with json.Unmarshal(data, &value) or json.NewDecoder(r).Decode(&value). The tags map each JSON key to its field.
Why are some fields pointers?
A pointer can be nil, so it tells a missing or null value apart from the zero value. Optional and nullable fields get pointers; slices are already nil-able and do not need them.
Why int and float64?
Whole numbers in every sample become int; if any sample has a decimal the field becomes float64. Change int to int64 if your IDs can exceed the range of int on 32-bit platforms.