Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
● GO STRUCTS · 100% BROWSER-BASED

JSON to Go

Paste a JSON sample and get Go structs, instantly and entirely in your browser. Optional fields, nullability and nested types are inferred from the sample — and anything the sample cannot settle is reported rather than guessed.

JSON sample
TypeScript interface
Type definitions will appear here

Go structs from a sample

Generates type ... struct with `json:"..."` tags, exported field names, and omitempty on optional fields. Acronyms follow Go convention — ID, URL, API.

Optional and nullable fields become pointers so absent can be told apart from zero.

What a sample cannot tell you

Types are inferred from one sample. A field absent from your sample will be absent from the output, and a field that happens to hold only whole numbers will be typed as an integer even if it can hold decimals. Paste the widest sample you have. For a guarantee rather than an inference, start from a JSON Schema.

What Go output looks like

Generated from two sample records, one of which has an extra field and a null. This is the actual output, not an illustration:

type Root struct {
	ID       int64    `json:"id"`
	UserName string   `json:"userName"`
	IsActive bool     `json:"isActive"`
	Score    float64  `json:"score"`
	Tags     []string `json:"tags"`
	Address  Address  `json:"address"`
	LastSeen string   `json:"lastSeen"`
	Nickname *string  `json:"nickname,omitempty"`
}

type Address struct {
	City     string      `json:"city"`
	Postcode interface{} `json:"postcode,omitempty"`
}

The three things that differ by language

Large integers

Go has int64, so a large identifier survives — but only if the field is typed as an integer. Decoding into interface{} or map[string]any gives float64 and silently rounds it, which is the commonest way this bites.

Optional against nullable

Optional and nullable fields become pointers, so a missing value is distinguishable from the zero value. omitempty is added so a nil pointer is not serialised as null.

Names that are not identifiers

Field names are exported and acronyms follow Go convention — ID, URL, API — with a json tag preserving the original key.

Convert the same JSON to