JSON to Go Struct
Generate Go structs with json tags from a JSON sample, including nested structs and slices.
Paste or drop
Paste text below, or drop a file instead.
Choose an output
Generate Go structs with json tags from a JSON sample, including nested structs and slices.
Fine-tune
Optional — sensible defaults are already set.
About JSON to Go Struct
This tool generates Go struct definitions from a JSON sample, with exported PascalCase field names and json struct tags that map back to the original keys. Nested objects become their own named structs and arrays become slices.
When it helps
- Writing structs to unmarshal a REST API response with encoding/json.
- Modeling a JSON config file loaded at startup by a Go service.
- Bootstrapping types for webhook payloads from services like GitHub or Stripe using a captured example.
Tips
- Whole numbers become int64 and numbers with a decimal point become float64. If an ID can be very large or a price must be exact, adjust the type by hand.
- Fields that are missing from some array items get ,omitempty in the tag. Fields that are null in some samples become pointers, so you can tell absent from zero.
- Fields with mixed types across samples become interface{}, which is a sign the API is inconsistent and worth checking.
- The output starts with package main; change it to your package name.
Good to know
Quick answers about json to go struct in your browser.
encoding/json can only set exported fields, and in Go a field is exported when it starts with a capital letter. The json tag keeps the mapping to the original key, such as user_id.
Use a pointer when you need to tell a missing or null value apart from the zero value, for example a missing count versus a count of 0. The generator does this for fields it sees as null.
Yes. There is no sign-up, no watermark and no limit on how many files you process.
No. Files are read and processed locally in your browser, so they never leave your device.
Related tools
Part of the JSON, YAML & XML Tools collection.