Skip to main content

JSON to Go Struct

Paste JSON and get Go structs with JSON tags and omitempty. Pointers for nullable fields, separate or inline structs. Private, in your browser.

Paste JSON on the left. Add a second sample to find optional fields.

JSON input

Stays in your browser

Go code

The generated code appears here.

Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)

Next steps

Free Online JSON to Go Struct Generator

Create Go structs from a sample payload so you can decode an API response with encoding/json straight away. It gives developers a quick browser-based way to solve a focused json to go struct task before moving the result into a project.

How to generate Go code from JSON

Paste a JSON object or an array of objects into the input box and press Generate. Field names follow Go style (ID, URL, CreatedAt) and every field carries a json tag. Turn omitempty on or off, use pointers for nullable fields, and choose separate or inline nested structs.

One input, every language

Your JSON stays in the box when you switch the language tabs, and the code is generated again at once. Each language also has its own page, so you can bookmark the one you use.

How types are worked out

  • Whole numbers and numbers with decimals are told apart.
  • Add more samples with Add sample: a key missing from some samples becomes optional, and null makes a type nullable.
  • Arrays of objects are merged into one type, and nested objects become their own types named after the key.
  • Keys that are not valid names in the language (such as first-name or 2fa) are renamed and mapped back, never rejected.

Worked example

The sample JSON in the box above, generated with the default options:

{
  "id": 1,
  "name": "Ada",
  "email": null,
  "tags": ["x"],
  "address": { "city": "Pune", "pin": "411001" },
  "createdAt": "2026-01-15T10:30:00Z"
}
package main

type Root struct {
	ID int64 `json:"id"`
	Name string `json:"name"`
	Email *string `json:"email,omitempty"`
	Tags []string `json:"tags"`
	Address Address `json:"address"`
	CreatedAt string `json:"createdAt"`
}

type Address struct {
	City string `json:"city"`
	Pin string `json:"pin"`
}

Common mistakes

  • A single sample cannot show which fields are optional. Paste two or three different responses for a realistic result.
  • A value that is always null gives no type information, so it is treated as a nullable string. Change it by hand if it is something else.
  • Numbers are typed from the samples: 1 and 1.0 look the same in JSON, so use a sample with decimals where you need a float.

Frequently asked questions

Why are some fields pointers?
A pointer lets Go tell "missing or null" apart from a zero value. Fields that were null in a sample become pointers; switch the option off to use plain types.
What does omitempty do?
With omitempty, a field is left out of the JSON you write when it is empty. The tool adds it to fields that were optional or nullable.
Which package name is used?
The output starts with package main. Change the first line to the package you need.
Is my JSON uploaded?
No. The types are worked out in your browser. Nothing you paste is sent to a server.
How do I use this json to go struct tool?
Use the interactive controls above; processing stays in your browser and the result is intended as a practical starting point for development work.

More Formatters & Parsers

View all Formatters & Parsers tools →