JSON to Go Struct
Generate Go structs with multiple struct tags from any JSON object.
Struct Tags
What is a Go Struct with JSON Tags?
In Go, JSON deserialization uses struct tags to map JSON keys to Go fields. A struct tag like `json:"first_name"` tells encoding/json to map the JSON key first_name to the Go field FirstName. Without the tag, Go requires the field name to exactly match the JSON key (case-insensitive).
Writing Go struct definitions by hand for complex JSON responses is tedious. This tool generates the complete struct hierarchy from any JSON — including nested structs, slice types, and proper json: tags for every field. Paste any JSON object or API response and get ready-to-use Go types in seconds.
JSON to Go Struct Example
Input JSON:
json
{
"id": 1,
"name": "Ravi Kumar",
"active": true,
"address": { "city": "Surat", "country": "IN" }
}Generated Go struct:
go
type RootAddress struct {
City string `json:"city"`
Country string `json:"country"`
}
type Root struct {
Id int64 `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Address RootAddress `json:"address"`
}JSON to Go Type Mapping
| JSON type | Go type | Notes |
|---|---|---|
| string | string | Mapped directly |
| integer number | int64 | Whole numbers use int64 for safety |
| float number | float64 | Decimal numbers use float64 |
| boolean | bool | true/false → bool |
| null | interface{} | Nullable fields use the empty interface |
| object | Struct (named) | Nested objects become separate named structs |
| array of objects | []StructName | Typed slice based on first element |
| array of strings | []string | Primitive arrays use typed slices |
Common Use Cases
- ▸REST API integration — Paste an API response JSON and instantly get the Go struct needed to decode it with encoding/json.
- ▸Database model generation — Convert a database record JSON to a Go struct for use with sqlx or GORM.
- ▸Config file parsing — Generate a Config struct from a sample config.json to use with json.Unmarshal.
- ▸gRPC / protobuf bridging — Create Go types for JSON bridging layers between REST and gRPC services.
Using the generated struct:
go
import "encoding/json"
var result Root
err := json.Unmarshal([]byte(data), &result)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Name)