JSON to Go Struct Converter

Paste JSON to generate Go struct definitions with json tags. 100% client-side.

JSON Input
Go Struct Output
Paste JSON above to generate Go structs.

How to Convert JSON to Go Structs

  1. Paste your JSON into the input area on the left.
  2. Choose a mode — Struct (basic json tags), Inline Tags (compact), or Omitempty (add omitempty to all fields).
  3. Copy or download the generated Go code using the buttons above the output.
  4. Paste into your Go project and import encoding/json to 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 ,omitempty to 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"`.

Frequently Asked Questions

Go struct json tags are string annotations attached to struct fields using backtick syntax. They tell the encoding/json package how to marshal and unmarshal the field. For example, `json:"user_name"` maps the Go field UserName to the JSON key 'user_name'. Without tags, Go uses the exact field name, which is PascalCase and differs from the snake_case or camelCase common in JSON APIs.
The omitempty option in a json tag tells the encoder to omit the field from the JSON output if its value is the zero value for its type (empty string, 0, false, nil pointer, empty slice/map). This produces cleaner JSON payloads by excluding fields that have no meaningful value, which is useful for optional API request fields.
No. This converter runs entirely in your browser. Your JSON never leaves your device. There is no backend server, no logging, and no data storage.
JSON strings map to Go string, JSON booleans to bool, JSON numbers to float64 (Go's default for JSON numbers), JSON null to interface{}, JSON arrays to slices ([]string, []float64, etc.), and JSON objects to nested struct types. If a number looks like an integer, the tool generates int64 instead of float64.
Yes. The generated structs are fully compatible with Go's standard library encoding/json package. You can use json.Unmarshal to decode JSON into the struct or json.Marshal to encode the struct back to JSON. The json tags ensure correct field name mapping between Go's PascalCase and JSON's camelCase or snake_case conventions.