JSON → Go Struct
Convert JSON into Go structs with json tags, omitempty, and pointer types for nullable fields.
package main
type Address struct {
Street string `json:"street"`
City string `json:"city"`
Zip string `json:"zip"`
}
type Root struct {
ID int64 `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Active bool `json:"active"`
Score float64 `json:"score"`
Tags []string `json:"tags"`
Address Address `json:"address"`
Metadata interface{} `json:"metadata"`
}2
Structs generated
11
Total fields
enabled
JSON tags
Go structs and JSON: how Go's encoding/json package works
Go's standard library encoding/json package is one of the most elegant JSON-handling approaches in any compiled language. You define a struct that matches your JSON shape, add json struct tags to map camelCase JSON keys to PascalCase Go fields, and call json.Unmarshal. The package uses reflection to populate your struct at runtime, with no code generation required and no external dependencies.
The most common gotcha is the three-way distinction between a missing field (field absent from JSON), a null field (json: null), and a zero value (json: 0 or json: ""). Without pointer types, these are all indistinguishable: a missing string and an empty string both produce an empty string field. If your API uses null to mean "not set" and you need to detect that, use *string instead of string. This generator optionally adds pointer types for all fields to make this distinction available.
How to convert JSON to a Go struct: step by step
- 1Paste your JSON
Copy any valid JSON object or array and paste it into the left input area. Nested objects generate nested struct definitions automatically. - 2Set the root struct name
Type a name for the top-level Go struct. Use PascalCase following Go naming conventions: for example User, Response, or ApiResult. - 3Choose json tag style
Select whether to include json struct tags (json:"field_name"), add omitempty to all tags, or use pointer types (*string, *int) for fields that may be absent or null. - 4Copy the generated struct
Click Copy to grab the Go struct code. Paste it into a .go file in your project: it is ready to use with encoding/json immediately. - 5Use with json.Unmarshal or json.Decoder
Pass the struct type to json.Unmarshal(data, &myStruct) or json.NewDecoder(r).Decode(&myStruct). The json tags ensure correct field mapping from camelCase JSON keys to PascalCase Go fields.
Related Tools
JSON to TypeScript
Convert JSON objects into TypeScript interfaces or type aliases. RN-friendly types, optional fields, readonly, and multiple export styles.
CSS to React Native
Convert CSS rules to React Native StyleSheet objects. Handles shorthand expansion, property mapping, and flags unsupported properties.
RN Shadow Generator
Visually generate React Native shadow props for iOS and Android. Preview shadows in real time and copy platform-specific code.
RN Flexbox Playground
Interactively explore React Native flexbox. Tweak direction, wrap, alignment, and item properties: see live code output.
Frequently Asked Questions
- What are json struct tags in Go?
- Go struct tags are string literals in backticks after a field declaration that provide metadata for the encoding/json package. The json:"name" tag tells the JSON encoder/decoder to use the string name as the JSON key instead of the Go field name.
- What does omitempty do?
- The omitempty option in a json tag (json:"field,omitempty") tells encoding/json to omit the field from the JSON output when marshaling if the field value is the zero value for its type: empty string, 0, false, nil pointer, nil map/slice. It has no effect on unmarshaling.
- When should I use pointer types (*string, *int)?
- Use pointer types when a JSON field can be absent or explicitly null, and you need to distinguish between 'field not present' and 'field is zero value'. A *string is nil for absent/null JSON and points to the empty string if the JSON value is "".
- How does the generator handle nested JSON objects?
- Nested JSON objects generate separate Go struct types. They are referenced as fields in the parent struct: Go does not support inline anonymous struct types in generated code as a best practice.
- How are JSON arrays mapped to Go types?
- JSON arrays of objects generate []TypeName where TypeName is a corresponding Go struct. Arrays of strings become []string, arrays of numbers become []float64 or []int depending on content, and mixed arrays become []interface{}.
- What Go type is used for JSON numbers?
- Integer-looking numbers without decimal points generate int or int64. Numbers with decimal points generate float64. If a field contains both in a JSON array it uses float64.
- Is the generated code ready to use with encoding/json?
- Yes. Import encoding/json and call json.Unmarshal([]byte(jsonData), &myStruct) or use json.NewDecoder. The struct tags ensure the JSON keys map correctly to the Go fields.
- Is this tool free?
- Completely free. The conversion runs entirely in your browser: no data leaves your machine.
AlteredIdea vs alternatives
vs other online tools: Everything runs in your browser: private, instant, no account needed.
vs desktop apps: No install required. Works on any device.
vs paid tools: Completely free, unlimited use.