How to Use This Tool
Paste a response and get structs. Read the decisions panel, which lists the places one sample could not settle.
Exported names and tags are not optional
Go's encoding/json uses reflection, and reflection cannot set unexported fields. A field
called name is invisible to it; a field called Name is not. Unmarshal a
response into a struct with lowercase fields and you get no error and no data — every field sits at
its zero value.
So every field here is capitalised, and each carries a json:"original_key" tag so the
wire format is preserved. Without the tag, Go matches case-insensitively on the field name, which
happens to work for name and fails for user_id, because
UserId does not match user_id once the underscore is gone.
Where you need a pointer
Go has no undefined. Every type has a zero value, and after unmarshalling you cannot tell
these apart:
"retry_count": 0— explicitly zero"retry_count"absent entirely"retry_count": null
All three leave an int field holding 0. If your code treats 0 as "no retries configured"
and the API omits the key when it means "use the default", those are different situations you can no
longer distinguish.
The fix is *int: nil means absent or null, and a pointer to 0 means explicitly zero. It
costs an allocation and a nil check at every use, which is why you want it only where the distinction
matters — so this flags the fields where the sample shows a null, rather than making everything a
pointer.
No union types
A key that is a string in one array element and a number in another has no Go type. It becomes
interface{} (or any in modern Go), which pushes a type switch to every place
that reads it. That is worth knowing before you write the code rather than at the first failed type
assertion, so it is flagged.
If you control the API, this is a bug in the API. If you do not, a custom
UnmarshalJSON on a named type is the usual way to normalise it at the boundary.
Two more things worth checking
- Large integers. Go's
int64handles 19-digit IDs fine, which JavaScript cannot — but if the JSON was produced by a JavaScript service, the value may already have been corrupted before it reached you. Astringfield for IDs is safer at the boundary. - Timestamps.
encoding/jsonparses RFC 3339 intotime.Timeautomatically, so an ISO 8601 string with an offset can be typed astime.Timedirectly. Anything else — a Unix integer, a date with no offset — needs a custom unmarshaller, so it stays a string here and is flagged.
