JSON to Go Struct Converter
Convert JSON to Go structs online. Generates idiomatic Go structs with proper json tags and PascalCase field names.
Last updated:
Paste JSON above to generate idiomatic Go structs with proper `json` tags and PascalCase exported fields. Nested objects become nested structs. Runs entirely in your browser.
What is JSON → Go?
Converting JSON to Go structs generates the typed structs you need to marshal and unmarshal JSON with encoding/json. Every JSON key becomes an exported (PascalCase) Go field with a matching struct tag, so round-tripping preserves the original key names. Nested objects generate nested struct types, and arrays are typed as slices of the inferred element type.
How to convert JSON to a Go struct
- 1Paste your JSON sample into the input pane.
- 2The tool infers Go types (string, int, float64, bool, slices, nested structs) and adds json tags.
- 3Copy the generated struct into your package and rename the top-level type to match your domain.
- 4Use json.Unmarshal to decode responses into the struct, or json.Marshal to encode.
Use Cases
Decode API responses in Go
Turn a sample JSON response into the exact struct needed for json.Unmarshal, avoiding map[string]interface{} guesswork.
Define request bodies
Generate the struct for an incoming webhook or POST body so your handler gets typed, validated fields.
Model config files
Convert a config.json into a struct you can load at startup with strong typing and defaults.
Code Examples
Input JSON
{ "user_id": 7, "name": "Ada", "tags": ["a", "b"] }Generated struct
type Root struct {
UserID int `json:"user_id"`
Name string `json:"name"`
Tags []string `json:"tags"`
}Unmarshal usage
var r Root
if err := json.Unmarshal(data, &r); err != nil {
log.Fatal(err)
}Key Concepts
- Struct tags
- The `json:"..."` tag maps a Go field to a JSON key. Without it, Go would expect the JSON key to match the exported field name exactly (case-insensitively).
- Exported fields
- Only fields starting with an uppercase letter are visible to encoding/json. Lowercase fields are ignored during marshal/unmarshal.
- omitempty
- Adding `,omitempty` to a tag omits the field from output when it holds a zero value — useful for optional fields.
- json.Number
- By default numbers decode to float64. Use json.Number or a typed field to avoid precision loss on large integers.
Tips & Best Practices
- ▸Numbers in JSON are ambiguous — the tool guesses int vs float64 from the sample. Adjust manually if a field can be fractional.
- ▸Add `,omitempty` to optional fields so encoded output stays clean.
- ▸For deeply dynamic JSON, consider json.RawMessage to defer decoding of a sub-tree.
- ▸Field order in the struct doesn't affect correctness, but grouping related fields improves readability.
Frequently Asked Questions
Does the tool add json tags?
Yes. Every field includes a `json:"..."` struct tag matching the original JSON key so encoding/decoding round-trips correctly.
How are field names generated?
Original JSON keys are converted to PascalCase (e.g. user_name → UserName) to satisfy Go's exported-field convention.
Related Tools
JSON → TypeScript
Convert JSON to TypeScript interfaces instantly. Generate strongly-typed TS types from any JSON sample.
JSON → YAML
Convert JSON to YAML online. Preserve structure, comments-free, and ready to paste into Kubernetes or CI configs.
YAML → JSON
Convert YAML documents to JSON online. Supports YAML 1.2, multi-document streams, and produces pretty-printed JSON output.
JSON → CSV
Convert an array of JSON objects to CSV online. Headers are inferred automatically from all keys across records.
CSV → JSON
Convert CSV data to a JSON array of objects online. Auto-detects delimiter and quotes, preserves numeric types when requested.
Number Base
Convert numbers between binary, octal, decimal, and hexadecimal. Supports arbitrarily large integers using BigInt.