JSON to Go Struct Converter
Paste JSON to generate Go struct definitions with json tags. 100% client-side.
How to Convert JSON to Go Structs
- Paste your JSON into the input area on the left.
- Choose a mode — Struct (basic json tags), Inline Tags (compact), or Omitempty (add omitempty to all fields).
- Copy or download the generated Go code using the buttons above the output.
- Paste into your Go project and import
encoding/jsonto use immediately.
Understanding Go Struct Tags
Go uses struct field tags to control how the encoding/json package serialises and deserialises data. Without tags, the encoder uses the exact Go field name (PascalCase), which rarely matches JSON APIs that use camelCase or snake_case. This converter automatically generates the correct json tag for every field based on the original JSON key name, ensuring your Go code works with any JSON API out of the box.
Output Modes Explained
- Struct — Standard Go struct with
`json:"field_name"`tags. The default mode, compatible with all standard Go JSON workflows. - Inline Tags — Same as Struct but places all fields on a single line with the tag on the same line. Produces more compact output useful for reviewing many fields at once.
- Omitempty — Adds
,omitemptyto every json tag. When marshalling back to JSON, fields with zero values (empty string, 0, false, nil) are omitted from the output. Use this for optional API request payloads.
Go Type Mapping from JSON
- JSON string →
string - JSON integer number →
int64 - JSON floating-point number →
float64 - JSON boolean →
bool - JSON null →
interface{} - JSON array of strings →
[]string - JSON array of objects →
[]ChildStruct - JSON nested object → separate named struct
Using Generated Structs with encoding/json
Once you paste the generated struct into your Go file, you can use it immediately with the standard library. To decode a JSON API response: var result RootObject; json.Unmarshal(body, &result). To encode a struct to JSON for an HTTP request: data, _ := json.Marshal(myStruct). The json tags guarantee that Go field names like UserName correctly map to JSON keys like user_name or userName.
Naming Conventions in Go
Go requires exported (public) struct fields to start with an uppercase letter. This converter always generates PascalCase field names to ensure all fields are exported and accessible from other packages. The original JSON key is preserved verbatim in the json tag so round-trip serialisation is lossless. For example, the JSON key first_name becomes the Go field FirstName with tag `json:"first_name"`.
Handling Nested and Array Types
Nested JSON objects become separate Go struct definitions. The converter generates child structs before the parent so the file compiles immediately without reordering. Arrays of primitive values become Go slices ([]string, []float64). Arrays of objects become slices of a named struct type, with the struct automatically generated and included in the output. Empty arrays default to []interface{} since the element type cannot be inferred.
Go JSON vs. Other Languages
Go's approach to JSON differs from dynamic languages like Python or JavaScript. In Go, you must explicitly define the structure of your data as a struct before you can decode JSON into it. This strict typing catches mismatches between your expected schema and actual API responses at compile time or during testing. It also enables IDE autocompletion and safe refactoring. For comparison, see our JSON to TypeScript converter for a similar statically typed workflow, or JSON to Python Dataclass for Python's equivalent.
Working with the Go Ecosystem
The generated structs work with all major Go JSON libraries beyond the standard library: github.com/json-iterator/go for faster encoding, github.com/go-json-experiment/json (the experimental v2 API), and github.com/bytedance/sonic. All of these respect the standard json: struct tag format. If you use GORM for database access, you can combine json tags with gorm tags on the same field: `json:"name" gorm:"column:name"`.