JSON to Go struct
Turn a JSON sample into Go struct definitions with inferred types and tags.
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.