JSON to Go
- json tags
- Pointer fields
- Instant
Idiomatic structs with json tags, and pointers where keys are inconsistent.
Paste input on the left to see go.
Everything runs in your browser — nothing is uploaded.
About go
Generating Go structs from JSON produces exported PascalCase fields with json tags preserving the original keys. JSONic chooses int64 or float64 depending on whether the sample value is integral, and uses pointer fields with omitempty for keys that are missing from some array elements.
Paste JSON and get idiomatic Go structs: exported PascalCase field names, a json tag preserving the original key, int64 or float64 chosen by whether the sample value is integral, and pointer types with omitempty for keys that only appear in some array elements.
Questions
Why int64 rather than int?
JSON numbers have no declared width, and int is platform-sized. int64 decodes any integral JSON number identically on every architecture.
When does a field become a pointer?
When the key was missing from at least one element of an array of objects. A pointer plus omitempty lets you distinguish absent from zero-valued, which matters when the zero value is meaningful.
How are keys that are not valid Go identifiers handled?
They are converted to PascalCase with non-word characters removed, and the original key is preserved verbatim in the json tag, so decoding still matches.