JSON to Go Struct Converter
To convert JSON to a Go struct: paste JSON and get a type definition with json tags. String values become string, integers become int, decimals become float64, booleans become bool, nested objects become separate structs, and arrays become slices. Field names convert from snake_case/camelCase to PascalCase. Example: {"user_name": "John"} becomes UserName string `json:"user_name,omitempty"`.
Convert JSON to Go structs instantly. Generates properly typed Go struct definitions with json tags. Handles nested objects, arrays, snake_case to PascalCase conversion, omitempty, and null values. Presets for API responses, configs, and nested data.
JSON Input
JSON to Go Type Mapping
| JSON Value | Go Type | Example |
|---|---|---|
| "hello" | string | Name string `json:"name"` |
| 42 | int | Age int `json:"age"` |
| 3.14 | float64 | Price float64 `json:"price"` |
| true | bool | Active bool `json:"active"` |
| null | interface{} | Data interface{} `json:"data"` |
| [1, 2] | []int | Scores []int `json:"scores"` |
| ["a"] | []string | Tags []string `json:"tags"` |
| {...} | struct | Address Address `json:"address"` |
| [{...}] | []struct | Users []User `json:"users"` |
How to Use
- 1
Paste your JSON
Paste a JSON object or array into the input area, or click a preset (API Response, Config, Nested, Simple) to see an example
- 2
Configure options
Set the root struct name, toggle omitempty for json tags, and enable pointer types for null values
- 3
Review Go struct output
The generated Go struct definitions appear instantly with proper types, PascalCase field names, and json struct tags
- 4
Copy to your Go project
Click the copy button to copy the Go structs and paste them into your .go file
Frequently Asked Questions
- How does JSON to Go struct conversion work?
- The converter analyzes your JSON structure and generates Go struct definitions with proper types and json tags. String values become string, integers become int, decimals become float64, booleans become bool, and nested objects become separate named structs. Property names are converted from snake_case or camelCase to PascalCase (exported Go fields).
- How are JSON keys converted to Go field names?
- Go requires exported fields to start with an uppercase letter. The converter converts snake_case (user_name) and camelCase (userName) to PascalCase (UserName). The original JSON key is preserved in the json struct tag for marshaling/unmarshaling: UserName string `json:"user_name"`.
- What does omitempty do in json tags?
- The omitempty option in a json tag tells Go's JSON encoder to skip the field if it has a zero value (empty string, 0, false, nil). Enable this option when your API responses may omit optional fields. Example: Name string `json:"name,omitempty"` won't appear in JSON output if Name is empty.
- How are arrays of objects handled?
- When JSON contains an array of objects like [{"id": 1}, {"id": 2, "name": "Bob"}], the converter merges all objects to create a superset struct containing all possible fields. The array type becomes []StructName. This ensures the generated type can deserialize any element in the array.
- How are null values represented in Go?
- JSON null has no direct Go equivalent. By default, null becomes interface{} (any). Enable "pointers for null" to use *string, *int, etc. instead, which is the idiomatic Go approach for nullable fields. Pointer fields are nil when the JSON value is null and can be checked with if field != nil.
- Can I use this with nested JSON objects?
- Yes. Nested objects become separate Go structs. For example, {"address": {"city": "NY"}} generates both a Root struct and an Address struct. The Root struct references Address by type name. This produces clean, idiomatic Go code with proper type separation.