You are offline. Tools you have opened before keep working.
JSON to Go struct
Paste JSON and get Go structs with json tags. Field names follow Go conventions such as ID and URL, optional fields get omitempty and nullable values become pointers.
Free and private. Everything runs in your browser, nothing is uploaded.
Report a problem
How it works
Paste your JSONPaste a response from your API or open a .json file. Use Sample to see an example.
Adjust the optionsSet the name of the top level type and the options for this language. The code updates as you type.
Copy or downloadCopy the code into your project or download it as a file.
Structs that unmarshal correctly
Every field is exported, because encoding/json ignores unexported fields, and every field carries a json tag with the original key. Common initialisms are written the Go way, so user_id becomes UserID and image_url becomes ImageURL. Fields that are missing in some items get omitempty, so they are left out again when you marshal the struct.
Values that can be null become pointers, which lets you tell a missing value from a zero value. If you prefer plain values for optional fields, turn off the pointer option. Timestamps with a time zone become time.Time, which parses RFC 3339 text; other date formats stay string, because time.Time would fail on them.
Frequently asked questions
Why int64 for some numbers and int for others?
Whole numbers that fit in 32 bits become int. Larger values, like millisecond timestamps or big IDs, become int64 so they are never cut on any platform.
Is my JSON uploaded anywhere?
No. The types are generated in your browser. API responses with customer data or keys never leave your device.
How are optional fields detected?
If the JSON contains a list of objects, every object is compared. A field that is missing from at least one object is marked optional. With a single object, every field is treated as required.
What happens with fields that are always null?
The type cannot be known from the sample, so the field gets a general type such as unknown, object, Any or JsonElement. Add a sample where the field has a value to get a precise type.
Why is my 1.0 typed as a decimal number?
The tool looks at how the number is written. 1.0 or 2.5 become double or float, 1 becomes an integer. If a field is whole in some items and decimal in others, the decimal type is used.
Can I use the result in production code?
Yes, the code compiles as it is in the usual setups. Review names and types before you commit it, because a sample can never show every possible value.
Does it work offline?
Yes. After you open the page once, it keeps working without an internet connection.