CalcCafe

JSON to Go

Paste JSON and instantly get clean, idiomatic Go struct definitions with proper types and json tags.

Example

Given this JSON:

{
 "id": 1,
 "name": "Acme",
 "address": { "city": "NYC", "zip": 10001 }
}

You get:

type Root struct {
	ID   int   `json:"id"`
	Name  string `json:"name"`
	Address Address `json:"address"`
}

type Address struct {
	City string `json:"city"`
	Zip int  `json:"zip"`
}

How it works

It parses your JSON, infers Go types (int, float64, bool, string, slices, nested structs), and emits gofmt-style struct definitions. The top-level type is named Root, with nested objects and array elements promoted to their own named structs.

Good to know

JSON to Go takes a sample of JSON and turns it into ready-to-paste Go struct definitions, complete with json:"..." tags and inferred types. It's aimed at Go developers who are wiring up a client for a REST API, modeling a config file, or unmarshaling a webhook payload and don't want to hand-write nested structs from a raw response.

Reach for it whenever you have a real JSON example but no schema. Paste a representative response, click Convert, and you get a Root struct plus a separate named struct for every nested object and array element. Field names are converted to exported Go identifiers in CamelCase, common initialisms like ID, URL, API, HTTP and UUID are upper-cased to match Go conventions, and the original key is preserved in the json tag so encoding round-trips correctly.

Reading the output is straightforward: each type X struct block is one model. Slices show up as []Type, mixed-precision numeric arrays collapse to float64, and anything the tool can't pin down (nulls, empty arrays, arrays of mixed types) becomes interface{} so it stays valid Go you can tighten later. The status line tells you how many types were generated, and a parse error means your input isn't valid JSON.

One practical caveat: type inference is only as good as your sample. A field that is null in your example produces interface{}, and a key missing from one element of an object array is still captured because the tool merges keys across all elements. If a number is sometimes whole and sometimes fractional, paste an example that includes the decimal so you get float64 rather than a lossy int. Always review and adjust the generated structs before relying on them in production.

Frequently asked questions

How are arrays of objects handled?
The tool merges keys across all objects in the array (so fields present in only some elements are still captured) and generates one named struct used as the slice element type, e.g. []Contact.
How does it decide between int and float64?
Whole numbers like 42 become int, while numbers with a fractional part like 9.99 become float64. In a mixed numeric array, float64 wins so no precision is lost.
Is my data uploaded anywhere?
No — it runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

Does JSON to Go add omitempty to the struct tags?
No. The generated tags contain only the original JSON key name, such as `json:"email"`. If you want omitempty or other options you add them manually after pasting the output.
How does it handle null values in my JSON?
A field whose value is null is typed as interface{} because the underlying type cannot be inferred from null alone. You can replace it with a concrete or pointer type once you know what the field actually holds.
What does the tool name the top-level struct?
The root object is always named Root, and nested objects and array element types get their own names derived from the field key. If the JSON is a top-level array you get `type Root []ElementType`.
Are the generated structs already gofmt-formatted?
Yes. The output uses tab indentation and aligns field names, types and tags in gofmt style, so it should pass gofmt without changes.
Can it convert JSON where the same array holds different shapes of objects?
For arrays of objects it merges the keys from every element into a single struct, so optional fields present in only some elements are still included. Arrays mixing fundamentally different types fall back to []interface{}.
How are field names with hyphens, underscores or spaces converted?
The tool splits on any non-alphanumeric character and CamelCases the parts to form an exported Go identifier, while the json tag keeps the original key. A name starting with a digit is prefixed with an underscore to stay valid.
Will it generate pointers for optional fields?
No, it emits value types, not pointers. If you need pointer fields to distinguish missing from zero values, change the relevant types to pointers yourself.
Does the converter send my JSON to a server?
No. All parsing and code generation runs locally in the browser using JavaScript, so the input stays on your device and works offline after the page loads.

Related tools