formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

JSON to Go Struct

Paste a sample JSON object below and generate a Go struct with `json:"..."` tags. The tool infers a type for every field and creates a named struct for each nested object.

How the type mapping works

Each JSON value maps to a Go type: a whole number becomes int, a decimal becomes float64, a string becomes string, true/false becomes bool, and null becomes interface{}. Field names are exported (capitalised) so json.Unmarshal can set them, and the original key is preserved in a json:"..." tag.

Arrays and nested objects

An array becomes a slice of its element type, e.g. ["admin","dev"] gives []string. A nested object becomes its own named struct — "address": {...} produces an Address struct and an Address field on the parent. Review numeric fields: JSON has one number type, so an int guess may need to be float64 (or int64) depending on your real data.

Why generate instead of hand-write

Hand-writing structs for a large API response is slow and error-prone — a mistyped tag silently drops a field. Generating from a real sample gives you a correct skeleton in one step; then tighten types and add omitempty where you need it.

FAQ

Does one sample produce a complete struct?

It produces a correct starting point. A single sample cannot reveal fields that are optional or null in other responses, so check the struct against more examples and add omitempty where appropriate.

Why is a number typed as int, not float64?

JSON has a single number type, so the tool guesses int for whole numbers and float64 when it sees a decimal. If a field can be fractional, change it to float64 (or json.Number for precision).

How is a nested object handled?

Each nested object becomes its own named Go struct, and the parent gets a field of that struct type. This keeps the output idiomatic and reusable.

Is my JSON uploaded anywhere?

No. Generation runs entirely in your browser with JavaScript; nothing is sent to a server.