JSON to Go Struct Generator
Paste a JSON sample and get ready-to-use Go structs. Field names are PascalCased with json tags, nested objects become their own sub-structs, and arrays infer their element type as a slice. Rename the root struct and copy the result.
How to convert JSON to a Go struct
- Paste a JSON object into the input box.
- Optionally rename the root struct (defaults to AutoGenerated).
- Copy the generated structs or download them as a .go file.
Examples
Flat object
{"name":"Ada","age":36,"active":true}type AutoGenerated struct {
Name string `json:"name"`
Age int64 `json:"age"`
Active bool `json:"active"`
}Nested object
{"user":{"id":1,"name":"Ada"}}type User struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type AutoGenerated struct {
User User `json:"user"`
}Frequently asked questions
What does this tool do?
It reads a JSON sample and generates matching Go structs, inferring the type of every field and adding a json tag so you can unmarshal the same JSON straight into the struct.
How are JSON types mapped to Go types?
Strings become string, whole numbers become int64, numbers with a decimal point become float64, booleans become bool, and null becomes interface{}. Nested objects become named sub-structs and arrays become slices like []string.
How are nested objects and arrays handled?
Each nested object becomes its own named struct, named in PascalCase from its key and de-duplicated if it clashes. Arrays infer their element type from the first item, so an array of objects produces a sub-struct and a []SubType field, while an empty array becomes []interface{}.
Why are field names different from my JSON keys?
Go exports fields that start with a capital letter, so keys are converted to PascalCase, for example first_name becomes FirstName. The original key is preserved in the json tag so marshaling and unmarshaling still match your data.
Is my JSON sent to a server?
No. Parsing and struct generation run entirely in your browser, so your data never leaves your machine.
Why did I get an error instead of a struct?
The tool needs valid JSON with an object at the top level. Invalid syntax or a top-level array, string or number returns an error message instead of structs.
Related tools
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample. Infers nested objects, arrays and union types, then copy or download the .ts file. Runs in your browser.
JSON Schema Generator
Generate a JSON Schema from a JSON sample. Infers types, properties and required fields as draft-07, ready to copy or download. Runs in your browser.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.
Base58 Encoder
Encode and decode Base58 online with the Bitcoin alphabet. Convert text to Base58 or back, UTF-8 safe, no confusing 0 O I l. Runs in your browser.