JSON to Go Struct
Convert a JSON to a Go struct with `json:` tags and inferred types. Detects strings, ints, floats, bools, slices and nested structs. Everything in your browser.
How it works
Every JSON key becomes a struct field in PascalCase, since Go only serialises exported fields — the ones starting with a capital letter. The json:"..." tag keeps the original key around so that encoding/json still maps it correctly.
Types are inferred automatically: whole numbers become int, decimals become float64, arrays with a single element type become []T, and mixed or null arrays fall back to interface{}. Everything runs in your browser.
From JSON payload to a tagged struct
An API response landed on your desk and now you need the matching Go struct. Typing it by hand is tedious and treacherous: one typo in a json: tag and encoding/json says nothing at all, it just hands back the field's zero value, and you spend the afternoon wondering why created_at is empty. Paste the JSON, name the root type, and the struct comes out ready to drop into the file.
Every key becomes a PascalCase field, because Go only serializes exported fields, the ones starting with a capital, and the json: tag keeps the original name. Types are inferred from the sample values: whole numbers become int, decimals become float64, null becomes interface{}. That is where the trap sits. JSON does not separate integers from decimals, so a price that arrived as 10.0 is read as int and breaks on the first response carrying 10.5.
For arrays, leave a single representative element before pasting. With two or more objects in the same list the generator emits one struct per element (Post, Post2) and the field falls back to []interface{}. Keys that clash with a Go keyword or start with a digit pick up an underscore, becoming _Type or _2fa, and an underscore-initial field is unexported, so rename it before you compile. Everything runs in the browser.
Frequently asked questions
Why did my decimal field come out as int?
Does it generate pointers and omitempty?
Is the pasted JSON sent to a server?
Related Tools
JSON ⇄ Query String Converter
Convert a flat JSON object to a query string (?a=1&b=2) and vice versa. Supports a[]=1&a[]=2 array style. Everything in your browser.
JSON Lines → CSV
Convert JSONL (NDJSON) file to CSV, deriving headers from the union of all observed object keys.
JSON to Markdown Table Converter
Convert an array of JSON objects into a formatted Markdown table, with header and alignment. Paste the JSON and copy a table ready for READMEs and docs.
JSON to TypeScript
Convert a JSON to TypeScript interfaces with automatically inferred types. Detects strings, numbers, booleans, arrays, nested objects and union types. Everything in your browser.
TOML to JSON
Convert TOML to JSON. Supports strings, integers, floats, booleans, dates, arrays and nested tables. Useful to inspect configs or pipe them into scripts. Everything in your browser.
JSON ↔ XML Converter
Convert between JSON and XML preserving attributes via @attr and text via #text, with pretty-print of the resulting XML.