ToolFeather
Developer / SEORuns in your browser

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.

Quick presets

JSON to Go Struct

JSON
Go

Runs in your browser — nothing you enter is uploaded or stored.

ToolFeather · JSON → Go
Scratchpad auto-saved
Stored in this browser (localStorage)
Step-by-step~40s read

How it works — in four simple steps

No signup and nothing to install — it all runs in your browser.

1

Add your JSON

Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.

2

Set the options

Adjust the options above the boxes — the output updates instantly as you change them.

3

Check the result

Read the status line: it reports rows, keys and any value that couldn't be represented in Go.

4

Copy or download

Copy the Go or download it as a .go file. Nothing was uploaded at any point.

Pro tip

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.

JSON input
{
  "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 } ]
  }
}
Go output
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 JSONBecomes in Go
"user_id": 7UserId int64 `json:"user_id"`
"price": 9.5Price float64 `json:"price"`
Nested objectnamed struct type
"tags": ["a"]Tags []string
Sometimes nullpointer, e.g. *string
Key missing in some items`json:"key,omitempty"`
Mixed typesinterface{}

Things that trip people up

JSON vs Go at a glance

PropertyJSONGo
SpecificationRFC 8259 (2017) · ECMA-404Go encoding/json
File extension.json.go
Media typeapplication/jsontext/plain
Data typesstring, number, boolean, null, object, arraystring, int64, float64, bool, slices, structs
CommentsNoYes
NestingUnlimitedNamed structs

Frequently asked questions

5 answers
How do I convert JSON to a Go struct?
Paste your JSON and copy the generated structs into a .go file. Nested objects become their own struct types with json tags.
Why are some fields pointers?
Fields that are null in at least one sample become pointers, so a JSON null decodes to nil instead of being confused with an empty string or 0.
When is omitempty added?
When a key is missing from at least one object in an array, the tag gets ,omitempty so encoding skips it when it's the zero value. You can turn this off.
Does it use int or int64?
int64 for whole numbers and float64 for numbers with decimals, matching the widest JSON values safely on all platforms.
Is my data uploaded anywhere?
No. The JSON is parsed and converted by JavaScript in your browser tab; nothing is sent to a server, so it is safe for internal exports, customer lists and configuration files with secrets.