Boneyard Tools

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

  1. Paste a JSON object into the input box.
  2. Optionally rename the root struct (defaults to AutoGenerated).
  3. 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