JSON to Go Struct
ConverterConvert sample JSON to Go structs with json tags, nested types and omitempty option for typing API clients, config loaders and data model definitions.
type Profile struct {
Age int `json:"age"`
City string `json:"city"`
}
type AutoGenerated struct {
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Score float64 `json:"score"`
Tags []string `json:"tags"`
Profile *Profile `json:"profile"`
}Related Tools
About JSON to Go Struct
Go is strongly typed, so consuming a JSON API means defining matching structs first — slow and easy to mistype json tags. This tool parses your sample JSON locally in the browser and generates Go structs with json tags: field names become exported PascalCase, nested objects split into their own structs, arrays infer to slice types, with an optional omitempty switch.
How to Use
- Open the JSON to Go Struct tool
- Select the source and target formats
- Adjust the output options as needed
- Click the Convert button; results appear in real time
- Copy or export the result
Use Cases
- Consume REST APIs — Paste the JSON an API returns and instantly get a Go struct ready to Unmarshal into.
- Define config structs — Generate a struct from a config sample to load YAML/JSON configuration.
- Build scrapers/collectors — Model third-party responses quickly and skip hand-writing fields.
- Bootstrap gRPC/messages — Reverse-engineer a structure from sample data as a starting point for messages or DTOs.
- Learn Go type mapping — See at a glance which Go types map to each JSON type to aid learning.
- Model AWS SDK payloads — Paste an AWS SDK response JSON and generate Go structs for typed unmarshaling in Lambda functions.
- Generate API client types — Create Go structs from a REST API sample to build a typed client library without manual mapping.
FAQ
How are field names converted?
They become exported PascalCase per Go conventions, with common initialisms like Id/URL/API uppercased, while keeping the original json tag.
What does a null value infer to?
null infers to interface{} since the concrete type is unknown. Use a non-null sample for a more precise type.
What is omitempty for?
When enabled it appends ,omitempty to the json tag so empty fields are omitted on marshal — handy when many fields are optional.
Do I need to adjust the output?
It is standard Go code you can rename, retype or comment after copying. Integers default to int and decimals to float64; change to int64 etc. as needed.
Are time/date fields handled specially?
By default they are generated as string fields. If an API field uses a standard time format, switch it to time.Time with a declared format in the json tag and encoding/json parses it automatically.
What about empty or null values?
Sparse or null samples infer to interface{} to avoid compile errors. For precise types, provide a sample with representative non-null values.