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.

Producing sample JSON from a Go struct

When you set up an API mock or register a response example in Postman, you end up writing out by hand what JSON a struct definition will actually produce. This tool generates that shape as sample JSON from nothing more than the Go struct definition you paste in, covering nested structs, slices, `omitempty` and `json:"-"` alike.

**What matters here is that a Go field name does not necessarily become the JSON key.** A json tag takes precedence where one exists, and a field marked `json:"-"` never appears at all. Since `omitempty` drops a field when its value is the zero value, **the very set of keys can differ between two encodings of the same struct.** Reading the definition by eye therefore invites mistakes about the real shape of the JSON, and expanding it mechanically is exactly what this tool is for. The values it produces are representative ones for each type, so replace them with meaningful data before putting the output to use.

How to use it

  1. Paste the struct definitions Several related structs may be pasted together without trouble.
  2. Name the struct you want **Specify it when more than one is present. If you leave the field empty, the first struct is used.**
  3. Review the generated JSON Nested structs and slices come out fully expanded.
  4. Swap in your own values Representative values are filled in, so replace them with data that suits your purpose.

Tips for getting more out of it

  • 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.

Where it comes in useful

Setting up an API mock

**Fixing the response example before the server is written means the front-end work need not wait.**

Putting examples into documentation

It supplies the material to paste into a Postman example or an OpenAPI sample.

Confirming what a tag does

You can see in concrete form what `omitempty` or `json:"-"` actually produces.

Agreeing on a shape with the front end

Showing concrete JSON leaves less room for misunderstanding than handing over a type definition.

Terms in Go encoding

Json tag
The annotation attached to a field in the form `json:"user_id"`, which **names the key on the JSON side.** Without one, the field name is used as it stands.
Omitempty
A setting that **leaves the key out of the output entirely when the value is the zero value.** Note that a 0 or an empty string is dropped along with everything else.
Json:"-"
A setting that keeps the field out of the JSON. It serves to hide fields meant for internal use.
Zero value
The initial value fixed for each type: 0 for numbers, empty for strings, and nil for pointers and slices.
Slice
A sequence of variable length, which becomes an array in JSON. **A nil slice is written as `null`, which sets it apart from an empty array.**
Embedded field
The notation that pulls another struct in by writing only its type name. In JSON its fields appear at the same level as the parent's keys.

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.
Tool-kun

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.