JSON to Go struct

Turn a JSON payload into a Go struct with json tags, gofmt-aligned columns and omitempty where the sample says a field is optional.

json
Gogo
The result appears here

Questions

Why are nested objects anonymous structs?+

Because naming them would mean inventing names the sample never gave you. An anonymous struct is valid Go and pastes straight in; lift a nested one into a named type when you need to pass it around.

When do I get a pointer?+

When the sample showed null for that field. A pointer is the only way Go can tell an absent value from a zero one, which is why a nullable string comes out as *string rather than string.

Why int64 rather than int?+

Because JSON numbers are 64-bit floats and an id that fits today may not fit on a 32-bit build. Narrow it by hand where you know the range.

Related tools

The tools are free. So is most of the library.

1935 blocks and 989 pieces for shadcn/ui and Tailwind, built on the same tokens these tools write. Install one with a command and the code is yours.

No signup for the tools. MIT for free blocks, commercial licence for Pro.

Markdown version