OpenReplay Logo
12k
12k

JSON to Go converter

Convert any JSON sample into typed Go structs with json tags. Processed locally in your browser, nothing is uploaded.

Processed locally

About this tool

Go structs are the idiomatic way to model JSON in Go: each exported field carries a `json:"..."` struct tag that the standard `encoding/json` package uses to marshal and unmarshal data. This converter parses a JSON sample, infers a Go type for every value — `int` for whole numbers, `float64` for decimals, `string`, `bool`, `interface{}` for null or unknown, and `[]T` for arrays — and emits PascalCase exported field names while keeping the original key in the tag. Arrays of objects are merged into a single shape so the generated struct includes every key seen across the elements.

Use it to scaffold request and response types for an HTTP API, model a config file or webhook payload, or turn a sample document from a NoSQL store into typed structs you can paste straight into your package. Name the root struct, toggle `,omitempty` on the tags, and choose between separate named types for nested objects or inline anonymous structs — handy for quick one-off models versus reusable shared types.

Everything runs client-side in your browser — your JSON is parsed locally and never sent to a server.

Frequently asked questions

How are JSON types mapped to Go types?

Whole numbers become `int`, decimals become `float64`, strings become `string`, booleans become `bool`, and `null` (or anything unknown) becomes `interface{}`. Arrays become a Go slice `[]T` of the element type, and nested objects become named structs (or inline anonymous structs if you toggle that on).

Why are my field names like user_id turned into UserID?

Go exports fields that start with an uppercase letter, so keys are converted to PascalCase. Common initialisms — ID, URL, API, HTTP — are kept fully upper-cased to follow golint conventions, so `user_id` becomes `UserID` and `api_url` becomes `APIURL`. The original key is preserved in the json struct tag.

What does the omitempty option do?

Adding `,omitempty` to a struct tag tells `encoding/json` to leave that field out of the marshaled JSON when it holds its zero value (0, "", false, nil, or an empty slice/map). It only affects encoding, not decoding.