JSON to Go Struct Converter
Paste JSON and get Go structs ready for encoding/json: exported field names, json tags with the original keys, nested structs, pointers for nullable values and omitempty for optional ones.
JSON to Go Struct
Runs in your browser — nothing you enter is uploaded or stored.
Scratchpad auto-saved
How it works — in four simple steps
No signup and nothing to install — it all runs in your browser.
Add your JSON
Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.
Set the options
Adjust the options above the boxes — the output updates instantly as you change them.
Check the result
Read the status line: it reports rows, keys and any value that couldn't be represented in Go.
Copy or download
Copy the Go or download it as a .go file. Nothing was uploaded at any point.
Change ISO timestamp fields to time.Time — encoding/json parses RFC 3339 strings into it.
Features
Named types
Choose the root type name; nested objects become their own named types, and identical shapes are merged.
Ready-to-compile Go
Exported fields with json tags, gofmt-style alignment, and omitempty on keys that are sometimes missing.
Private by design
Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.
About the JSON to Go Struct
Go's encoding/json package maps JSON onto structs through exported fields and struct tags. Writing those by hand for a large response is tedious; this generator writes them from a sample. Each JSON key becomes an exported field in PascalCase (user_id → UserId, inStock → InStock) with a tag holding the exact original key, so marshalling round-trips.
Types are inferred across every element of every array: whole numbers become int64, numbers with a fraction float64 (mixed columns become float64), booleans bool, strings string, nested objects their own named struct, arrays []T. A value that is sometimes null becomes a pointer (*string, *Address) so you can tell "missing" from the zero value, and keys missing from some objects get ,omitempty. Values of mixed types fall back to interface{}.
Field names, types and tags are aligned in columns the way gofmt does it, and you can set the package name. Structs with identical fields are generated once and reused.
Examples
A payment webhook payload with a nested object, an optional field and a nullable value.
{
"event_id": "evt_1042",
"type": "payment.succeeded",
"created": 1792915200,
"data": {
"amount": 37.5,
"currency": "EUR",
"customer": { "id": "cus_77", "email": "ada@example.com" },
"metadata": null,
"items": [ { "sku": "TF-MUG", "qty": 2 }, { "sku": "TF-CAP", "qty": 1, "gift": true } ]
}
}package webhooks
type Event struct {
EventId string `json:"event_id"`
Type string `json:"type"`
Created int64 `json:"created"`
Data Data `json:"data"`
}
type Data struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Customer Customer `json:"customer"`
Metadata interface{} `json:"metadata"`
Items []Item `json:"items"`
}
type Customer struct {
Id string `json:"id"`
Email string `json:"email"`
}
type Item struct {
Sku string `json:"sku"`
Qty int64 `json:"qty"`
Gift bool `json:"gift,omitempty"`
}This output was produced by the converter on this page with root Event in package webhooks — load it with the “Webhook” preset above and change any option to see the effect.
How JSON maps to Go
| In JSON | Becomes in Go |
|---|---|
"user_id": 7 | UserId int64 `json:"user_id"` |
"price": 9.5 | Price float64 `json:"price"` |
| Nested object | named struct type |
"tags": ["a"] | Tags []string |
Sometimes null | pointer, e.g. *string |
| Key missing in some items | `json:"key,omitempty"` |
| Mixed types | interface{} |
Things that trip people up
- Initialisms. Go style writes ID and URL in capitals (UserID); the generator produces UserId. Rename if you follow golint conventions — the json tag keeps decoding correct either way.
- Big numbers. JSON numbers above 2⁵³ are imprecise in JavaScript, where this runs; if you have 64-bit IDs, they may already be rounded in the sample. Use json.Number or string IDs.
- time.Time. ISO timestamps are generated as string. Change the field to time.Time — encoding/json parses RFC 3339 strings into it.
- interface{} vs any. Since Go 1.18, any is an alias for interface{}; both compile.
JSON vs Go at a glance
| Property | JSON | Go |
|---|---|---|
| Specification | RFC 8259 (2017) · ECMA-404 | Go encoding/json |
| File extension | .json | .go |
| Media type | application/json | text/plain |
| Data types | string, number, boolean, null, object, array | string, int64, float64, bool, slices, structs |
| Comments | No | Yes |
| Nesting | Unlimited | Named structs |
- JSON: Numbers are parsed as IEEE-754 doubles in JavaScript, so integers above 9,007,199,254,740,991 (2⁵³ − 1) lose precision.