JSON to Go
Generate Go structs with json tags from a JSON sample: nested objects, arrays, nullable pointers and four naming conventions.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
package main
type RootOwner struct {
Name string `json:"name"`
Email interface{} `json:"email"`
}
type RootItems struct {
Sku string `json:"sku"`
Price float64 `json:"price"`
Note *string `json:"note"`
}
type Root struct {
ID int64 `json:"id"`
Name string `json:"name"`
IsActive bool `json:"is_active"`
Score float64 `json:"score"`
Owner RootOwner `json:"owner"`
Tags []string `json:"tags"`
Items []RootItems `json:"items"`
Meta interface{} `json:"meta"`
}Summary: Types 3 · Fields 13 · Name clashes 0
What this tool does
- Paste a sample API response and get Go structs with json tags instead of typing every field by hand.
- Keep the difference between "the key was absent" and "the value is the zero value": optional fields become pointers (*int64, *string) so a round trip loses nothing.
- Turn awkward API keys (kebab-case, embedded ID / URL abbreviations) into exported field names that follow Go community conventions.
- Make sure encoding/json can actually fill the struct: generated field names are always exported, and the original JSON key stays in the tag.
Example
Input
{"id":1,"name":"UniKit","tags":["a","b"]}Output
package main
type Root struct {
ID int64 `json:"id"`
Name string `json:"name"`
Tags []string `json:"tags"`
}Types come purely from the JSON: a homogeneous array becomes []string, a heterogeneous one degrades to []interface{}, and null or partially present fields are expressed as pointers.
Frequently asked questions
Why did id become ID instead of Id?
Go convention writes common initialisms in full caps, and this tool knows id, url, api, json, http, uuid and friends. If you dislike that style, switch the naming convention to snake_case or kebab-case and the initialisms stay untouched.
Why are some fields *int64 instead of int64?
Pointers appear in two places: the key is null in some array elements ([{"a":1},{"a":null}] gives *int64), or the key is missing from some array elements (*int64). If a key is only ever null across the sample it carries no type information and degrades to interface{} rather than a pointer. Slices, maps and interface{} are already nilable, so they never get an extra pointer.
What happens when the objects in an array have different shapes?
The field list is the union of all elements, and a key present in only some of them becomes a pointer. If one key holds different types across elements (a number here, a string there), that field falls back to interface{}.
Can the root value be an array or a scalar?
An object or an array of objects works, and the root struct name is whatever you typed (Root by default). A scalar root (number, string, null) is rejected because no struct can be inferred from it.
Is my JSON uploaded anywhere?
No. Parsing and code generation run entirely in your browser with JavaScript, the page makes no network requests, and it keeps working offline.
Keywords:jsongogolangstructjson tagsjson to goJSON 转 Go结构体golang 结构体代码生成