Skip to content
snip tools

JSON to Go struct generator

Generate Go structs with json tags from JSON. Nested objects, arrays and optional fields are inferred. Runs in your browser.

Runs 100% in your browser
 

How to convert JSON to Go

  1. Paste your JSON. Paste a JSON object or array.
  2. Name the root struct. Optionally rename the root struct.
  3. Copy the structs. Copy the generated Go into your project.

Structs, tags and exported names

Consuming a JSON API in Go means writing a struct for every object plus the json:"…" tags that map snake_case keys onto Go fields — busywork that's easy to get subtly wrong. This generator does it from a sample: each object becomes a struct, keys are converted to exported PascalCase identifiers (Go only marshals exported fields), and the original key is preserved in the tag so json.Marshal/Unmarshal round-trips exactly. Keys absent from some objects in an array get ,omitempty.

The number problem Go forces you to confront

JSON has a single number type; Go has many. Decode JSON into an interface{} and every number becomes a float64 — which quietly mangles large integer IDs once they exceed what a float can represent exactly. Generating concrete structs is the fix: this tool emits int for values that are always whole and float64 only for ones with decimals, so an ID stays an integer. It's worth a glance at the inferred numeric types, since a field that's whole in your sample but fractional in production should be widened to float64 by hand.

Nullable and mixed fields

A value that's sometimes null becomes a pointer (*T) so the zero value and "absent" stay distinguishable; an always-null or mixed-type field falls back to interface{} for you to tighten. Prefer TypeScript? The JSON to TypeScript generator emits interfaces instead, and the JSON formatter validates a sample before you generate from it.

Frequently asked questions

How does it generate Go structs?
It infers a struct for each JSON object, with exported fields and json:"…" tags matching the original keys. Arrays of objects are merged into one struct, and integer-only numbers become int while decimals become float64.
How are optional and null values handled?
A key missing from some objects in an array gets ,omitempty on its tag. A value that is sometimes null and sometimes a single type becomes a pointer (*T); always-null or mixed types become interface{}.
Are field names valid Go?
Yes — keys are converted to exported PascalCase identifiers, and the original key is preserved in the JSON tag so marshalling round-trips.
Is my JSON uploaded?
No. Generation runs entirely in your browser.