JSON to Go Converter Online — Generate Struct

Generate Go structs from any JSON payload — exported PascalCase fields, idiomatic `json:"field_name"` tags, nested structs, and encoding/json compatibility. 100% in your browser.

What is a JSON to Go converter?

A JSON to Go converter reads a JSON sample and emits typed Go structs that mirror the JSON shape — exported PascalCase fields, backtick struct tags, nested structs, and slices for arrays. The output drops straight into a Gin, Echo, Fiber, gRPC-Gateway, or net/http project and unmarshals with encoding/json without any reflection surprises.

Writing struct definitions by hand from a 200-field API payload wastes hours and is bug-prone — a single typo in a json tag silently zero-values a field at runtime. OpenFormatter's converter walks the JSON tree once, generates idiomatic Go, and runs entirely in your browser so internal API responses never leave your machine.

How to generate Go structs from JSON — 4 steps

  1. Paste a real JSON response. Use a representative sample — type inference quality depends on it. Booleans must be true/false (not 0/1), numbers must be unquoted.
  2. Click Convert. The tool emits a Root struct plus one separate struct per nested object, with PascalCase fields and matching json tags.
  3. Copy and paste into your IDE. Each struct is independent — split them across files in the same Go package.
  4. Unmarshal. var r Root; json.Unmarshal(data, &r) — that is all encoding/json needs once exported fields and json tags are in place.

JSON to Go type mapping

Sample JSON

{
  "id": 42,
  "name": "Ada Lovelace",
  "active": true,
  "score": 98.5,
  "address": { "city": "London" },
  "tags": ["admin", "engineer"]
}

Generated Go struct

package main

type Root struct {
	Id      int      `json:"id"`
	Name    string   `json:"name"`
	Active  bool     `json:"active"`
	Score   float64  `json:"score"`
	Address Address  `json:"address"`
	Tags    []string `json:"tags"`
}

type Address struct {
	City string `json:"city"`
}

Idiomatic structs

Exported PascalCase fields with backtick `json:"field_name"` tags — exactly what encoding/json reads to map JSON keys to Go fields without extra reflection.

Nested structs

Every nested JSON object becomes its own typed struct so you can split files within the package and see the full hierarchy at a glance.

Client-Side Only

JSON is parsed in JavaScript inside the browser. Internal API responses, tokens, or PII never reach a server.

Common use cases

  • check_circleGenerating Gin / Echo / Fiber HTTP request and response models from a frontend JSON payload
  • check_circleBuilding gRPC-Gateway transcoded REST handlers from a JSON spec
  • check_circleProducing AWS Lambda or Cloud Functions request/response structs
  • check_circleModelling Stripe, Slack, or GitHub webhook payloads as typed Go structs
  • check_circleGenerating Kubernetes operator CRDs from sample JSON manifests
  • check_circleBuilding Kafka, NATS, or RabbitMQ consumer message structs
  • check_circleModelling a third-party SaaS API for a Go SDK or CLI client
  • check_circleGenerating GraphQL response shapes when graphql-go codegen is overkill

Why client-side generation matters

The JSON you paste often contains real customer data, OAuth tokens, signed URLs, or internal field names you do not want indexed by a third-party converter. OpenFormatter generates the Go entirely in JavaScript on your device — open the Network tab in DevTools and you will see zero requests when you click Convert. Safe for enterprise use, safe behind a corporate proxy, safe when the API contract is itself confidential.

Need other Go tooling?

Format JSON, parse JSON inside Go code, or generate types for other systems languages — all browser-side.

Frequently Asked Questions

What JSON tag format is used?

Each field gets a backtick struct tag of the form `json:"field_name"` matching the original JSON key exactly. The Go field itself is PascalCase (required for export so encoding/json can see it). For example, the JSON key user_id becomes UserId int `json:"user_id"` — the wire format stays snake_case while Go code uses idiomatic PascalCase.

How are optional fields handled (pointer vs omitempty)?

The generator emits non-pointer types because that produces the cleanest output. To make a field truly optional, change int to *int (a pointer) — encoding/json then writes null when the pointer is nil. To omit a zero-value field from the marshalled JSON, add ,omitempty to the tag: `json:"name,omitempty"`. Use both together (*string with omitempty) for fields that may be absent in the wire format.

Why is the tool emitting int instead of int64?

JSON numbers within the int range are emitted as int because that is the most common Go choice and works on both 32-bit and 64-bit platforms (Go widens int automatically on 64-bit). For high-precision IDs (Twitter snowflake, Stripe IDs) change to int64 manually — encoding/json maps JSON numbers to int64 without precision loss up to 2^53.

How do I unmarshal the generated struct?

var root Root; err := json.Unmarshal(data, &root) — that is everything encoding/json needs once exported PascalCase fields and json tags are present. To stream from an io.Reader use json.NewDecoder(r).Decode(&root). Wrap unknown fields with json.RawMessage if you want to defer typed parsing.

How are JSON arrays mapped?

Arrays of objects become []ClassName slices using a generated nested struct. Arrays of strings become []string, arrays of mixed primitives become []interface{}. encoding/json handles slices natively — no extra setup.

How are nested JSON objects modelled?

Each nested object becomes its own top-level Go struct so you can split them across files in the same package. The parent struct holds the nested type by value (Address Address `json:"address"`) — change to *Address to make it nullable on the wire.

How are JSON keys with dashes or reserved Go words handled?

A JSON key like "user-id" is converted to UserId in the Go struct and the original key is preserved in the json tag. Reserved Go words are not actually reserved as exported field names (you can have a field called Type or Range) so no renaming is needed for the field — only the tag needs to match the JSON.

Is the JSON uploaded to your servers?

No. Conversion runs entirely in your browser via JavaScript. Open DevTools → Network and click Convert — no requests are made. JSON containing API keys, internal field names, or PII never leaves your machine.

JSON to Go Converter Online — Generate Struct