Zero Signup ToolsFree browser tools

Developer Tools

JSON to Go Struct Converter

Convert JSON to Go structs in your browser. Smart type inference, json tags, omitempty, pointer for nullable, int64 vs int, interface{} vs any.

0 chars

Output options

Live preview updates with every change. All inference happens in your browser; the JSON you paste is not uploaded.

Used as the name of the root struct. Converted to a valid exported Go identifier automatically.

Adds "package X" at the top, useful when pasting into a fresh .go file.

Integer type

JSON numbers without a fractional part. int64 is the safe default for IDs and timestamps; int matches the host word size.

Any type

Used for empty arrays and heterogeneous unions. `any` is the built-in alias for `interface` from Go 1.18 onwards.

Indent

gofmt uses tabs; pick spaces only if your editor strips tabs.

How to use

  1. Paste a JSON value into the input on the left, or click Load sample JSON to see a worked example.
  2. Read the generated Go on the right; one struct is emitted per nested object shape, with the root named after the Root struct name field.
  3. Pick the integer type (int64 for safe IDs and timestamps, or int to match the host word size) and the any type (interface{} for older Go, or any for Go 1.18 and later).
  4. Toggle Pointer for optional / null so missing or null fields are emitted as pointer types, and Add omitempty so encoding/json drops zero values.
  5. Optionally prepend a package line, pick tabs (gofmt) or spaces, and sort fields A to Z if you prefer alphabetical output.
  6. Click Copy Go to put the full output on your clipboard, ready to paste into a .go file.

About this tool

JSON to Go Struct Converter turns any JSON value into idiomatic Go struct declarations entirely in your browser. Paste an API response, a config file, a fixture, or a copied object literal, and the tool parses it with the browser's native JSON parser, walks the resulting tree, and emits one named struct per object shape with field types mapped to Go: string to string, boolean to bool, integer numbers to int64 (or int when you prefer), non-integer numbers to float64, and heterogeneous arrays or unknown values to interface{} (or to any from Go 1.18 onwards). Field names follow the Go style guide: keys are converted to PascalCase exported identifiers, and common initialisms recognized by the standard library and golint (ID, URL, API, JSON, HTTP, HTTPS, IP, UUID, DNS, TLS, SSL, RPC, SMTP, SQL, UI, TCP, UDP, OS, IO, DB, AWS, GCP, SDK, and more) are uppercased wholesale, so user_id becomes UserID and api_url becomes APIURL. Each field carries a json struct tag that preserves the original JSON key (json:"snake_case_name") so encoding/json round-trips without surprises. Nested objects are extracted into their own named structs with names derived from the parent key, so the output reads top-down from the root and references are easy to follow. Arrays infer their element type from the union of every element seen, so a list of mixed objects produces a merged shape and an empty array becomes []interface{} (or []any). When the same key appears in some elements of an array but not others, the optional setting promotes the field to a pointer and adds ,omitempty to the json tag, which lets you distinguish unset from the Go zero value when decoding. Fields that ever appear as JSON null are also promoted to pointers so the decoder cannot confuse null with the zero value. Output options control the integer type, the any type, whether to prepend a package declaration, whether to indent with tabs (gofmt style) or four spaces, and whether to keep fields in their original JSON order or sort them A to Z. Go reserved words and keys with hyphens, spaces, or leading digits are normalized automatically so the result compiles. Useful for typing API responses without writing boilerplate, modeling third-party JSON payloads, generating fixtures and DTOs, scaffolding gRPC gateway or REST clients, and saving time on every pull request that adds a new endpoint. Parsing and inference run locally on your device, so the JSON you paste here never leaves your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools