JSON to Go

Convert JSON to Go structs with json tags, Go-style names like UserID and pointers for optional fields. Free, runs in your browser.

How to convert JSON to Go

  1. Paste a JSON object or array, for example a response from the API you are calling.
  2. Set the name of the root type.
  3. Copy the generated Go code into your project.

What you get

Tips for accurate results

The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.

Frequently asked questions

Is my JSON sent to a server?

No. The code is generated in your browser, so API responses and other private data never leave your device.

How do I use the generated structs?

Paste them into your package and decode with json.Unmarshal(data, &value) or json.NewDecoder(r).Decode(&value). The tags map each JSON key to its field.

Why are some fields pointers?

A pointer can be nil, so it tells a missing or null value apart from the zero value. Optional and nullable fields get pointers; slices are already nil-able and do not need them.

Why int and float64?

Whole numbers in every sample become int; if any sample has a decimal the field becomes float64. Change int to int64 if your IDs can exceed the range of int on 32-bit platforms.