Go Struct to JSON Sample Generator

Paste a Go struct definition with json tags to automatically generate matching sample JSON data. Supports nested structs, slices, omitempty, and json:"-", handy for API mocks and Postman examples.

Usage tips

  • Paste multiple structs together and nested field types are resolved automatically, recursively generating sample objects (if a definition can't be found, an empty object {} is used and a warning is shown).
  • Specify a target struct name to pick which struct becomes the root when your input contains more than one (the first struct that appears is used if left blank).
  • Fields tagged json:"-" are excluded from the JSON output. Fields with omitempty still have their key emitted as usual, so remove it manually if you don't want it.
  • The generated values are just placeholders based on the type (strings become "example", numbers become 1, and so on). Replace them with real data if you need an actual API response example.
  • This tool is the reverse of the sibling JSON to Go Struct Converter. It lets you quickly turn a struct defined in a Go handler into a sample payload for your frontend or QA team.

Frequently asked questions

Manually turning a Go API response struct into JSON by hand is easy to get wrong — you can misread a type or a json tag, especially with deeply nested structures. Auto-generating it lets you share an accurate sample payload with your frontend or QA team much faster.

If the definition for a referenced struct isn't found in the input, that field's value is emitted as an empty object {} and a warning message is shown on screen. Paste the source struct alongside it to get a correctly nested sample.

omitempty is only a Go-side instruction to omit zero values during encoding, so the key itself is still emitted in the sample JSON as usual. A field tagged json:"-", however, is fully excluded during encoding, so it's left out of the sample JSON too.

No, they're purely placeholders that satisfy the type. Strings become "example", integers become 1, floating-point numbers become 1.5, and booleans become true — fixed values you should replace as needed for real use.

No — this tool is a lightweight parser based on regular expressions and line-by-line analysis, not a real Go syntax parser (AST). It doesn't handle complex notation like multi-line type declarations or nested anonymous structs, so treat it as a quick draft generator rather than a precise one.
ツールくん

Side Note — The Reverse of JSON to Go Struct Conversion

When building a web API in Go, the response shape is typically defined as a struct paired with json tags. But when a frontend developer or QA engineer wants to check how the API behaves, reading through Go code and mentally converting each field's type into JSON is tedious and easy to get wrong.

This tool performs the exact reverse of its sibling, the "JSON to Go Struct Converter". Paste a Go struct definition and it generates a sample JSON payload with key names following the json tags and placeholder values matching each field's type — ready to drop straight into a Postman example or a frontend mock.

That said, this isn't a real Go compiler — it's a lightweight parser built on regular expressions and line-by-line analysis. It handles simple field definitions and nested structs pasted together in the same input, but complex notation like anonymous nested structs or multi-line type declarations may not parse correctly. Treat it as a starting draft and verify the final shape against the actual Go source.

→ Browse all trivia