JSON to Go Struct Converter
Paste a JSON object (or JSON array) to automatically generate the corresponding Go struct definitions with json tags.
Usage tips
- When all elements of an array are objects, their keys are merged into a single struct. Keys missing from some elements automatically get an `omitempty` json tag.
- The root type name defaults to "Root", but you can rename it to anything you like. Struct names for nested objects are generated automatically by converting their property names to PascalCase.
- JSON null is emitted as `interface{}` since Go has no native nullable primitive type. Consider switching to a pointer type if you need stricter handling.
- The output is a lightly column-aligned draft. Running it through `gofmt` after pasting will align it to your project's standard style.
- Paste a sample JSON response from your API as-is to quickly get a starting point for the response struct used in your Go code.
Frequently asked questions
Side Note — Why Go Pairs Structs With json Tags
Go is a statically typed language, and when it works with JSON, the standard library's `encoding/json` package relies on the mapping between struct fields and their json tags to encode and decode data. Manually writing out a struct for an external API's response shape is a repetitive chore that grows every time a field is added, and it has been a recurring task across many Go projects.
This tool parses the structure of a sample JSON payload and automatically generates the corresponding struct definitions and json tags, cutting down on that repetitive work. A well-known tool in the same space is quicktype, which supports converting to types in multiple languages — but for the simpler case of pasting a sample API response and quickly getting a Go struct out of it, a focused single-purpose tool has its own convenience.
Because Go has no language feature for making a struct field optional, the common approach for JSON fields that might be missing is to add `omitempty` to the json tag, or to use a pointer type (like `*string`) to distinguish a zero value from "no value at all". The generated struct is only a mechanical inference from structure, so treating nullability and future API changes as something to verify and adjust by hand against the actual specification is standard practice.