Generate Go structs from JSON
Decoding JSON in Go means defining a matching struct with the right field types
and json:"..." tags by hand — tedious and error-prone for nested payloads. This
tool infers typed Go structs from a representative JSON sample so you can
paste them straight into your project.
How it works
The generator walks the sample and maps each value to a Go type, building nested structs as it goes:
| JSON | Go type |
|---|---|
| integral number | int64 |
| fractional number | float64 |
| mixed numeric array | []float64 |
| string | string |
| boolean | bool |
| object | its own exported struct (pointer) |
| array of T | []T |
| mixed array | []interface{} |
Field names are PascalCased, with common initialisms like ID and URL
capitalised the way Go’s style guide expects, and every field gets a
json:"originalKey" tag.
Example
This JSON:
{ "id": 7, "user": { "name": "Sam" } }
generates:
type Root struct {
ID int64 `json:"id"`
User *User `json:"user"`
}
type User struct {
Name string `json:"name"`
}
Because the types are inferred from one sample, treat the output as a strong starting point. All inference happens in your browser — your JSON is never uploaded or stored.