Generate Go structs from JSON
Idiomatic Go structs with proper PascalCase field names, inferred types, and json struct tags — ready to paste into your project.
type Address struct {
City string `json:"city"`
Country string `json:"country"`
}
type Root struct {
UserId int64 `json:"user_id"`
Name string `json:"name"`
Email string `json:"email"`
IsActive bool `json:"is_active"`
Roles []string `json:"roles"`
Address Address `json:"address"`
}How to generate Go structs from JSON
Stop typing structs by hand. Paste a real JSON sample and get fully-tagged type Foo struct declarations with idiomatic encoding/json tags.
- 01
Paste a JSON sample
Use a representative example — API response, config, log entry.
Inputs parse through the native
JSON.parsereviver chain — strict RFC 8259. Any syntax error returns line and column for the exact offending byte.sampleRFC 8259JSON.parsestrictliveinput · raw.json · RFC 8259{"user_id":1}loaded · parsed RFC 8259RFC 8259 · ready - 02
Name the root struct
Defaults to
Root. Pick PascalCase domain names.Indent options run through
JSON.stringify(value, null, n); the second argument lets you sort, transform, or omit keys via a replacer if you ever wire one in.PascalCaseindentJSON.stringifyliveorderednaming · optionsUser · livetype User struct { UserID int64 `json:"user_id"` }options applied · livelive - 03
Toggle omitempty
Enable to add
,omitemptyto every JSON tag — useful when serializing optional fields.Large documents stream through a
useMemowith stable hashing so options re-apply instantly — no full re-parse if only formatting changes.omitemptymemoisedinstantdiff-friendlydeterministictags · renderedomitempty · readyField string `json:"field,omitempty"`
rendered · livediff-friendly - 04
Copy or download .go
Drop into a
.gofile. Marshaling/unmarshaling round-trips cleanly with the original JSON.Download is a
Blobwithapplication/json; copy uses the Async Clipboard API. Both round-trip identically to what the page rendered.copydownloadclipboardblob.jsonexport · copiedready · done✓ Copied ✓ Saved: types.go
shipped · ready to shipsuccess
Production-grade JSON, the right way
Stick to RFC 8259
Strict JSON has no NaN, Infinity, comments, or trailing commas. If you need those, look at JSON5 or JSON Repair.
Preserve key order for diffs
JavaScript preserves insertion order, but two parsers shouldn’t be assumed equal. Use Sort JSON Keys before diffing or hashing.
Big integers lose precision
JS numbers lose precision past 2^53−1. Transport large IDs as strings or use BigInt.
Escape inside HTML
When inlining JSON inside <script>, escape </ to <\/ so HTML parsing doesn’t close your tag early.
Validate at boundaries
Trust the wire as little as possible. Run incoming JSON through a schema (Zod / Pydantic) before it touches business logic.
Minify in production
Minify removes whitespace; gzip removes redundancy. Together they typically shrink JSON payloads 70–85% over the wire.
When to generate Go structs
Anywhere you'd otherwise type structs by hand to consume JSON.
HTTP client codegen
Generate response types for your API client wrapper. Output round-trips losslessly through JSON.parse + JSON.stringify, so the file you save is byte-identical to what you see. Streaming parsers, jq pipelines, and Postgres jsonb columns all accept the result without complaint.
fewer interface{}gRPC gateway response
Quickly model response payloads for handlers. Pairs perfectly with sort-keys + diff for review-friendly fixtures in CI. Whitespace-only churn disappears and reviewers see real changes, which keeps PR comments focused on logic rather than indentation.
cleaner PR diffsWebhook handlers
Type the body of a Stripe / Slack / GitHub webhook for safer code. Handles emoji and non-ASCII via UTF-8 throughout — your data survives copy-paste between editors, terminals, and IDEs. Combining marks and ZWJ sequences come out the other side intact.
RFC 8259 validConfig files
Bind a config.json to a typed Config struct. Re-parses on every keystroke so syntax errors are caught at the exact character. Strict RFC 8259 — no trailing commas, no comments, no unquoted keys — keeps downstream parsers happy.
round-trip safeTest fixtures
Type test fixture JSON for compile-time safety in tests. Streams large documents without a server round-trip — privacy stays in the tab. Heavy parsing runs through useMemo so even 5 MB payloads keep the editor responsive.
schema-friendlyDatabase row scans
Generate structs that match `jsonb` columns or document-store records. Output is byte-stable: same input plus same options always produces identical bytes, ideal for content-addressed caches and snapshot tests. Downloads ship with the application/json MIME so editors apply syntax highlighting.
production-readyFrequently asked questions
[]T where T is inferred from the first element. For mixed-type arrays, edit to []interface{}.Something missing?
Tell us what you need. We ship the top requests every two weeks.