Skip to content
100% local

JSON to Go struct

Turn a JSON sample into Go struct definitions with inferred types and tags.

Input
Output

JSON to Go struct

Paste a JSON sample and this tool generates matching Go struct definitions with json tags. It infers int, float64, string, bool and null for every field, builds named or inline structs for nested objects, and works out slice types for arrays — including slices of objects, which get their own reusable struct.

Options shape the generated code. Name the root struct yourself, or let the tool derive one. Choose how tags are written — keep the original key, or convert it to snake_case or camelCase regardless of how the source field was named. Turn on "Add omitempty" to append it to every tag, and "Pointers for optional fields" to mark fields missing or null in parts of the sample with a pointer type. When an array's objects have slightly different fields, "Merge array element shapes" combines them into one struct with the extra fields marked optional, instead of giving up on the element type. For values it can't pin down, choose interface{}, the any alias, or json.RawMessage for deferred decoding.

This is the step before writing an API client or config loader in Go: paste a real response or sample config and get a starting struct instead of typing field names and tags by hand. Nested structs can stay as separate named types for reuse elsewhere in your package, or render inline when a shape is only used once. A comment with the original JSON key is available for fields whose tag no longer matches it.

Everything runs locally in your browser — the JSON you paste, which might include real API responses or internal config, is never uploaded. Copy the result, download it as a .txt file, or move the output back into the input to refine the sample and regenerate.

FAQ

Does it handle nested objects and arrays?
Yes. Nested objects become their own named struct (or an inline anonymous one, if you enable that), arrays become slices, and a slice of objects reuses one struct when every element shares the same shape.
What happens when an array's objects don't all have the same fields?
With "Merge array element shapes" on (the default), the tool combines every field it saw across the elements into one struct, marking fields that were missing in some elements as optional. Turn it off and the tool falls back to a dynamic element type instead.
Can I control how JSON tags are named?
Yes, with the JSON tag format option: keep the original key exactly as it appears in the sample, or convert every key to snake_case or camelCase.
What type do I get for a field the tool cannot infer?
interface{}, the any alias, or json.RawMessage, depending on the option you pick — RawMessage is useful when you want to decode that field yourself later.
Is my JSON uploaded anywhere?
No. Struct generation runs entirely in your browser — the JSON you paste never leaves your device.