Convert JSON to Go
Turn a sample response into Go structs.
About this converter
Structs with the json tags already written, which is the tedious half of decoding a response in Go.
Optional fields become pointers, and that is deliberate. Go has no undefined: a missing string and an empty string both arrive as "", so a plain field cannot tell you which happened. A *string can — nil means absent, and a pointer to "" means present and empty. Fields seen in every record stay plain values, because a pointer you never need to check is just friction.
Numbers become float64, since JSON has one number type and nothing in a sample says whether 42 is an integer or a rounded price. Change it to int where you know better — that is a judgement about your data, not something a generator can make for you.
Frequently asked questions
Why are some fields pointers?
Because they were missing from some of the records you pasted. Go has no undefined, so a missing string and an empty string are the same value — only a pointer distinguishes them. Fields present in every record are plain values, which keeps the struct readable.
Why is every number a float64?
Because JSON has exactly one number type and a sample cannot tell you more. 42 might be a count or a rounded amount. float64 is what encoding/json uses when it has no type to aim at, so it is the safe default — change the ones you know are integers.
What does omitempty do?
It leaves the field out when encoding if the value is empty. It is added on the optional fields so a struct round-trips back to something like the JSON you started with. Note that it treats zero, false and "" as empty too, which is occasionally not what you want.
Does what I paste get sent anywhere?
No. Everything runs in your browser, on your own machine. Nothing is uploaded and nothing is logged. That matters more here than on most pages — source code, database queries and internal data are exactly the things that get pasted into tools like this, and most of them are a form that posts to a server.