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.