JSON to Go Struct Converter

Paste a JSON sample and get Go structs with exported fields and json:"…" tags, ready for encoding/json. Nested objects become their own structs and arrays become slices.

Input Code
Ready - Type or paste code in the left panel
Output Code
Ready - Type or paste code in the left panel

How to convert JSON to Go

  1. Paste your JSON into the left panel, or click Load Sample.
  2. Go is already selected as the output on the right.
  3. Click Convert, then Copy Output.

Example

This JSON:

{ "id": 101, "name": "Ada Lovelace", "email": "ada@example.com", "active": true, "balance": 250.75,
  "address": { "city": "London", "postcode": "N1 9GU" }, "tags": ["admin", "beta"] }

becomes:

package model

type Root struct {
	Id      int64    `json:"id"`
	Name    string   `json:"name"`
	Email   string   `json:"email"`
	Active  bool     `json:"active"`
	Balance float64  `json:"balance"`
	Address Address  `json:"address"`
	Tags    []string `json:"tags"`
}

type Address struct {
	City     string `json:"city"`
	Postcode string `json:"postcode"`
}

How JSON types map to Go

JSON valueGo type
"text"string
101int64
250.75float64
truebool
{ … }a new struct named after the key
["a", "b"][]string

Decoding JSON into the struct

var root model.Root
if err := json.Unmarshal(data, &root); err != nil {
	return err
}
fmt.Println(root.Address.City)

Go only decodes into exported fields (capitalised names), which is why every field starts with a capital letter and the original key sits in the tag.

Optional fields and arrays of objects

Paste an array of objects instead of a single object and the generator compares all items: fields missing from some items become pointers with omitempty, so you can tell "absent" from a zero value.

Things to check after generating

Is my JSON sent anywhere?

The code is generated in your browser; your JSON never leaves your computer. See the privacy policy.

Frequently asked questions

How do I convert JSON to a Go struct?

Paste the JSON on the left, keep Go selected on the right and click Convert. Copy the structs into your package and use json.Unmarshal to decode.

Why are the field names capitalised?

encoding/json can only set exported fields, and exported names start with a capital letter. The json tag keeps the original key name.

How are optional fields handled?

If you paste an array of objects, fields missing from some items become pointer types with omitempty in the tag.

Is my JSON uploaded?

No. Go structs are generated in your browser.

Other languages: JSON to Java · JSON to TypeScript · JSON to Python · JSON to C# · JSON to Kotlin · all languages

Share Content

Choose what to share and generate an instant link

🔥 One-time link Content deleted from server after first view
✉️
Uploading to server…