JSON to Go Struct

Convert JSON to Go structs with encoding/json tags

Paste JSON and get Go structs back instantly. Field names are exported in PascalCase while a struct tag preserves the original JSON key, so the result works directly with encoding/json. Nested objects become their own structs and the time import is added when a timestamp is detected.

Options on this page

Output format: Struct + JSON tags — Exported fields with `json:"..."` tags for encoding/json.

OptionWhat it does
Root Struct NameNames the top-level Struct.
Package NameEmitted as the package clause at the top of each file.
Field Naming ConventionOne of PascalCase, camelCase, Preserve Original. Defaults to PascalCase.
Type for null valuesEither interface{} or string, used when a key is null in every sample.
Add ,omitemptyAppend ,omitempty to each JSON tag so zero-valued fields are skipped when marshalling.

How JSON values map to Go types

JSON valueGo type
stringstring
integerint
integer beyond 32 bitsint64
decimalfloat64
true / falsebool
ISO-8601 timestamptime.Time
array[]T
objectnested struct
nullinterface{} (configurable)

Example

Input JSON

{
  "id": 12345,
  "product_name": "Wireless Mouse",
  "price": 24.99,
  "in_stock": true,
  "tags": ["electronics", "accessories"],
  "manufacturer": {
    "name": "Acme Corp",
    "country": "US"
  }
}

Generated Go

package main

type Product struct {
	Id           int          `json:"id"`
	ProductName  string       `json:"product_name"`
	Price        float64      `json:"price"`
	InStock      bool         `json:"in_stock"`
	Tags         []string     `json:"tags"`
	Manufacturer Manufacturer `json:"manufacturer"`
}

Frequently asked questions

Why are my field names capitalized?

Go only marshals and unmarshals exported fields, meaning ones whose names start with a capital letter. The generator capitalizes every field for that reason and puts the original JSON key in the struct tag, so product_name in your JSON maps to a ProductName field.

What does the ,omitempty option do?

It appends ,omitempty to each json struct tag, which tells encoding/json to leave a field out of the output when it holds its zero value — an empty string, 0, false, or a nil slice. Useful for compact payloads, but it makes a genuine zero indistinguishable from an absent field.

Is my JSON uploaded anywhere?

No. Parsing, type inference, and code generation all run in your browser using JavaScript. Your JSON is never sent to a server, and there is no account, tracking, or storage beyond your own browser.

Does it cost anything?

No. The generator is free to use with no sign-up and no usage limits.

How are nested objects handled?

Each nested JSON object becomes its own named type, derived from the key it appeared under. Arrays of objects are widened across every element, so a field that is a whole number in one element and a fraction in another gets a type that holds both.

Other languages