JSON to Go

Generate Go structs from JSON.

About the JSON to Go

Paste a JSON response and get Go structs back, each field carrying a json tag so the original key casing survives. Nested objects are lifted into their own named types, field names are exported and Go-cased (id becomes ID), and numbers land as int64 or float64 depending on the sample. Set the root type name before generating. Everything is inferred in your browser from the sample you provide.

How to use the JSON to Go

  1. Paste a representative JSON sample into the input panel, or press Sample to load an example.
  2. Set Root name to the type name you want for the top-level struct.
  3. Press Generate.
  4. Press Copy, or Download to save types.go.

Frequently asked questions

Does the output include json struct tags?
Yes. Every field gets a `json:"originalKey"` tag, so exporting the field as UserID in Go still marshals to user_id or whatever the sample used.
Why is one of my fields interface{}?
Because the sample only ever showed null there, so there was nothing to infer from. Supply a sample where the field has a real value, or set the type by hand.
Will the generated code compile as-is?
It is types only — no package clause, no imports, and no marshalling helpers. Paste it into a file that already declares its package and it compiles.
How are optional fields handled?
The generator sees a single sample, so a key that is merely absent in other responses is not detected as optional. Add ,omitempty to those tags, or switch the field to a pointer, yourself.
Is my JSON sent anywhere?
No. Type inference runs in your browser tab, so pasting a real production response does not put it on someone else's server.

Related tools