JSON to Go Struct
Paste JSON, get Go structs with json tags.
Go
Examples
Questions
How are field names made?
Each key becomes an exported PascalCase name, with Go initialisms in capitals: user_id becomes UserID and api_url becomes APIURL. The json tag keeps the original key, so decoding still matches.
Why int64 for some numbers and float64 for others?
A whole number becomes int64 and a number with a decimal point or exponent becomes float64. If an array mixes both, the field is float64. A whole number too big for int64 becomes json.Number, so no digits are lost.
When is omitempty added?
When a key is missing from some objects in an array. Those objects are merged into one struct, and the key is tagged omitempty.
Why is a field typed any?
Its value was null, or it had different types in different places. JSON alone cannot say what it should be, so pick the right type yourself.
Related tools
- JSON to TypeScriptPaste JSON, get TypeScript interfaces.
- JSON Formatter & ValidatorFormat, minify, check and repair JSON, with errors shown by line and column.
- JSON to YAML ConverterConvert JSON to YAML, or YAML to JSON.
- JSON DiffCompare two JSON documents and see every added, removed and changed value by path.