JSON to Go Struct Generator
Paste JSON and instantly generate Go struct definitions with json tags, nested objects, and proper type inference
Paste any JSON payload and get typed Go structs back — with correct field names, json tags, nested objects, and proper type inference for ints, floats, bools, and nulls. Set the root name, toggle omitempty, and pick inline or separate nested structs to match your project style. And everything runs in your browser. Nothing gets uploaded.
How It Works
The parser walks through every key-value pair in your JSON. Strings map to string, whole numbers to int64, decimals to float64, booleans to bool, and nulls to interface{}. Nested objects become their own struct types, and arrays turn into Go slices with the correct element type. Field names get converted to PascalCase automatically, and the original JSON key is preserved in the struct tag.
Examples
Simple User Object
A basic API response with a few flat fields — the kind you'd get from a /users endpoint.
{
"id": 42,
"username": "gopher",
"email": "[email protected]",
"active": true
}
type Root struct {
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Active bool `json:"active"`
}
Nested Address with Tags Array
When your JSON has objects inside objects plus an array of strings — a pretty common pattern for profile data.
{
"name": "Alice",
"address": {
"street": "742 Evergreen Terrace",
"city": "Springfield",
"zip": "62704"
},
"tags": ["admin", "verified"]
}
type Root struct {
Name string `json:"name"`
Address struct {
Street string `json:"street"`
City string `json:"city"`
Zip string `json:"zip"`
} `json:"address"`
Tags []string `json:"tags"`
}
E-Commerce Product with Nested Array of Objects
A more realistic payload — product data with pricing, an array of variant objects, and nullable fields.
{
"sku": "SHOE-001",
"title": "Running Shoe",
"price": 89.99,
"in_stock": true,
"discount": null,
"variants": [
{ "size": "10", "color": "blue" },
{ "size": "11", "color": "red" }
]
}
type Root struct {
Sku string `json:"sku"`
Title string `json:"title"`
Price float64 `json:"price"`
InStock bool `json:"in_stock"`
Discount interface{} `json:"discount"`
Variants []struct {
Size string `json:"size"`
Color string `json:"color"`
} `json:"variants"`
}
Who Uses This
Turning third-party API responses into typed Go structs without hand-writing each field and tag.
Converting JSON config files into Go structs for CLI tools and infrastructure automation.
Quickly scaffolding request/response models when building Go APIs that consume JSON from frontends.
Learning how Go's type system maps to JSON by seeing the struct output change as they edit the input.
Common Mistakes
Trailing commas, single quotes instead of double quotes, or unquoted keys will all cause a parse error. Run your JSON through a validator first if you're not sure it's clean.
A value like 10.0 gets typed as float64, not int64. JSON doesn't distinguish between integer and float — if there is a decimal point, Go treats it as a float. Remove the .0 in your input if you need an integer type.
The default name is "Root" which is fine for testing, but you'll want to change it before copying into your codebase. A struct called Root sitting in production code is a code review red flag.
The tool infers the array element type from the first item. If your first object has fewer fields than others in the array, you'll get an incomplete struct. Paste the most complete object or the full array.
Technical Details
- Processing: 100% client-side — nothing leaves your browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Max Input Size: Limited only by browser memory (tested up to 5 MB JSON)
- Type Inference: string, int64, float64, bool, interface{}, nested structs, slices
- Output Format: Downloadable as
.gofile with proper formatting
Frequently Asked Questions
How do I convert JSON to a Go struct?
Paste your JSON into the left panel and click Generate. The tool reads every key and value, picks the right Go type for each one, and builds a struct definition with json tags. You can copy the result or download it as a .go file.
What does omitempty do in Go struct tags?
Adding ,omitempty to a json tag tells Go's encoder to skip that field when marshalling if it holds a zero value — empty string, 0, false, nil, or an empty slice. It keeps your JSON output clean by dropping fields that don't carry real data.
How does the tool handle null values in JSON?
Null values become interface{} because Go can't infer the actual type from null alone. If you know the field should be a string or int, you can change the type manually after generating. Some developers prefer using pointer types like *string for nullable fields — that's a quick manual edit.
Should I use inline or separate nested structs?
Inline works great for quick prototyping or when the nested object is only used in one place. Separate structs are better when you want to reuse the type elsewhere in your code, or when the nesting gets deep enough that readability suffers. There is no performance difference — it's purely about code organization.
Is my JSON data safe when using this tool?
Completely. The conversion runs entirely in JavaScript inside your browser tab. No data gets sent to any server. You can disconnect from the internet and the tool still works — that's the simplest proof it is not phoning home.