JSON to Go Converter – Free, Online, Private
Generate Go structs with json tags from a JSON sample, using pointers for values that were null and int64 for integers.
How to convert JSON to Go
- Paste the JSON you decoded with encoding/json.
- Copy the struct definitions, including the json tags.
- Adjust omitempty or pointer fields if the sample did not show every null you care about.
Struct layout
Each JSON object becomes a struct type. Field names are exported PascalCase so encoding/json can see them, and the original key is preserved in a json struct tag. Integers in the sample become int64, other numbers become float64, and strings and bools map directly. Nested objects are separate struct types rather than anonymous structs, which keeps gofmt-friendly files when the payload is deep. Arrays become slices. An empty array has no element type to copy, so the element falls back to a wide type the generator can still print.
Null and absence
Go's zero values collide with JSON null and with missing keys. A field that was null in the sample is emitted as a pointer so nil can represent null. A field that was missing on some array elements is also optional in spirit: the generator marks it optional and the tag can omit it. encoding/json will still set a missing non-pointer field to the zero value, which is why people switch numbers to pointers when 0 is meaningful. This page cannot know that from one sample where id was 42. Change int64 to *int64 by hand when zero matters.
Worked example
Root contains ID int64 with json:"id", Name string, Active bool, Tags []string and Address Address. The nested struct holds City and Zip. Tags is a slice of string. There is no package clause battle: the snippet is the types only, ready to drop under package dto. If your module uses a code generator from OpenAPI, prefer that for production and use this page when you have a body and no spec. The inference matches the JSON to TypeScript page, but the printed syntax is Go.
What you still edit
time.Time is not inferred from date strings. json.Number is not used; large integers that do not fit the sample's JavaScript number are already rounded before this page sees them. Ask the API for strings if you have 64-bit ids bigger than 2^53. Map types are not guessed: an object is a struct, even if the keys look dynamic. A truly dynamic object should be map[string]any. The generator runs in the browser, so private payloads used to sketch a client stay on the machine.
Frequently asked questions
Does it emit omitempty?
Optional fields inferred from missing keys get omitempty in the tag. Fields that were present are required in the tag.
Why int64 and not int?
int changes width between platforms. int64 matches a typical JSON integer better for ids and counts.
Can I name the root struct?
The root type is Root. Rename it after pasting; nested types keep names taken from their keys.
Is the JSON uploaded?
No. Struct text is generated in the page from JSON.parse.