UTILS.
100% in-browser
🐹

JSON to Go Struct

Convert a JSON sample into typed Go structs with json tags. Infers int64, float64, bool, nested structs and slices in your browser.

output

About this tool

Paste a JSON sample and this tool generates ready-to-use Go structs, complete with `json:"field"` tags for every key. Everything runs locally in your browser, so your JSON is never uploaded anywhere.

The generator calls JSON.parse and walks the result recursively: strings become string, booleans become bool, whole numbers become int64 and numbers with a decimal become float64, null becomes interface{}, arrays become a slice of the first element's type ([]interface{} when empty), and each object becomes its own named nested struct. Field names are converted to exported PascalCase (with common initialisms like ID and URL upper-cased) while the original key is preserved in the json tag.

Use it to bootstrap Go models from an API response or config file, then tidy the types by hand where needed. Because JSON has no separate integer type, a value like 1.0 is read as an integer; add a decimal (1.5) if you want float64.

Frequently asked questions

How are numbers typed?
A parsed value with no fractional part becomes int64; a value with a decimal becomes float64. JSON cannot distinguish 1 from 1.0, so both read as int64.
What happens with nested objects and arrays?
Each object becomes a separate named struct; arrays become a slice of the first element's type, or []interface{} if the array is empty or the element is null.
Are the field names valid Go?
Keys are converted to exported PascalCase and the original key is kept in a json tag, so JSON round-trips correctly even for names like user_id or first-name.
Is my JSON sent to a server?
No. Parsing and code generation happen entirely in your browser; nothing is uploaded or stored.

More tools