JSON to Go Struct
Paste JSON to generate ready-to-use Go structs with json tags and nested types — instantly and entirely in your browser.
Updated
How to use JSON to Go Struct
The JSON to Go Struct converter turns a JSON sample into ready-to-use Go type definitions, instantly in your browser. Paste any JSON object and the tool generates a struct with exported PascalCase fields, correct Go types, and json:"..." tags that preserve the original keys. Nested objects become their own named structs and arrays become slices, so the full shape of your data is represented. It is a fast, private way to bootstrap Go models from an API response without hand-writing every field.
- Optionally set the name for the root struct.
- Paste your JSON object into the input area.
- The Go struct definitions are generated automatically as you type.
- Review the field names, types and json tags in the output.
- Copy the generated code into your Go project and adjust types if needed.
Your data never leaves your device — 100% private processing.
How JSON types map to Go types
Go is statically typed, so every JSON value must be assigned a concrete Go type. This converter applies the conventional mapping used by most Go developers: JSON strings become string, booleans become bool, and the special value null becomes interface{} because Go has no direct null. Numbers are the interesting case — JSON has a single number type, but Go distinguishes integers from floats, so a value with no fractional part is mapped to int and a value with a decimal point is mapped to float64. Arrays become slices of the element type, and nested objects are promoted to their own named structs so the whole document is strongly typed.
| JSON value | Go type | Example |
|---|---|---|
| "hello" | string | Name string |
| 42 | int | Count int |
| 3.14 | float64 | Ratio float64 |
| true | bool | Active bool |
| null | interface{} | Value interface{} |
| [ ... ] | slice | Tags []string |
Why struct tags matter
Go field names must be exported (start with a capital letter) for the encoding/json package to read and write them, but JSON keys are usually lowercase or snake_case. The struct tag json:"original_key" bridges this gap: it tells the JSON encoder which key to use on the wire while letting you keep idiomatic PascalCase field names in Go. Without the tag, marshalling a field named UserId would emit "UserId" instead of the expected "user_id", breaking compatibility with the original API. This converter always emits the correct tag for every field, so the generated structs round-trip your JSON exactly. After generating, you can refine types — for example swapping int for int64 or adding omitempty to a tag — to match your precise requirements.
Worked examples
Convert a flat object
Inputs: { "id": 1, "name": "Ada" }
Result: type AutoGenerated struct { Id int `json:"id"` Name string `json:"name"` }
Nested object
Inputs: { "meta": { "count": 2 } }
Result: type Meta struct { Count int `json:"count"` }
Glossary
- Struct
- A Go composite type that groups named fields together, used to model structured data like a JSON object.
- Struct tag
- A string annotation on a Go field, such as json:"name", that controls how the field is encoded and decoded.
- Exported field
- A struct field whose name starts with a capital letter, making it visible to other packages including encoding/json.
- Slice
- Go’s dynamic array type; a JSON array is represented as a slice of the element type.
- interface{}
- Go’s empty interface, used here for JSON null or values whose type cannot be inferred.
Related reading
Frequently Asked Questions
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Why use JSON to Go Struct?
- Generate complete Go structs from a JSON sample in one step
- Automatic json tags preserve the original key names for correct marshalling
- Nested objects become named structs and arrays become typed slices
- Sensible type mapping — int, float64, bool, string and interface{}
- Runs entirely client-side, so your JSON never leaves your browser
Common use cases
- Bootstrap Go request and response models from an API JSON example
- Convert a config file’s JSON into a typed Go struct for unmarshalling
- Generate structs for a third-party webhook payload you need to parse
- Quickly scaffold types while prototyping a Go service
- Learn how a given JSON shape maps to idiomatic Go types
Related Developer Tools
JSON to TypeScript Types
Convert JSON to TypeScript interfaces online. Infers types, nested objects, and arrays automatically. Free, private JSON-to-TS generator in your browser.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
JSON Schema Validator
Validate JSON data against a JSON Schema online. Get clear, path-based error messages for every violation. Free, private JSON Schema validator.
Regex Tester
Test and debug regular expressions online. See live matches, capture groups, and replace output. Free, private, instant.
Base64 Encoder & Decoder
Encode text or files to Base64, or decode Base64 strings back to text. Fast, free, and runs entirely in your browser.
URL Encoder / Decoder
Encode and decode URLs and URL components online. Convert special characters to percent-encoding and back instantly — free, private, and fast.
Explore all Developer Tools.