JSON to Go structs

Paste a JSON sample and get Go structs with json tags, nested types named for you and optional fields as pointers with omitempty.

Paste JSON in first; its readable text, tables and types appear here.

How to generate Go structs

  1. Paste the JSON in View & search.
  2. Open Text, table & types and choose Go.
  3. Set the root type and the package name.
  4. Copy the code into your project.

What you get

Each JSON object becomes a struct with exported field names and json tags that keep the original keys, so encoding/json decodes the data as is. Fields that are missing in some items of a list become pointers with omitempty, integers become int64 and decimals float64. When the root of the JSON is a list, a slice type is added for it, for example type Root []RootItem.

Checked with go vet

pastejson's automated tests write the Go generated for dozens of samples and run go vet on it in continuous integration, so the code you copy is valid Go.

Use a representative sample

Types come from the sample, so include records that have the optional fields and values that are sometimes null; they become pointers or interface{} where the data is mixed. If the same structure appears under several keys, quicktype merges it into one named type instead of repeating it, which keeps the generated file short and easy to review before you commit it.

Questions

Are the json tags included?

Yes. Every field has a json tag with the original key.

How are optional fields represented?

As pointers with omitempty when a field is missing in some items.

Can I choose the package name?

Yes. Set it in the options; the default is main.

Is my data uploaded?

No. Generation runs in your browser.

Does it support other languages?

pastejson offers TypeScript, Zod and Go.