Convert Go Structs to JSON!

Input Go (Golang) structs to generate example JSON that follows their json tags! Handy for API tests and mock request bodies.
Go struct
Result
 

Convert Go Structs to JSON!

Paste Go struct definitions and get an example JSON document built with the same rules encoding/json applies when marshaling: json:"..." tag names, fields hidden with -, the ,string option, unexported lowercase fields and flattened embedded structs.

It is handy for producing a curl body from a Gin, Echo or net/http request struct, preparing samples for gRPC-Gateway or REST docs, and spotting fields whose tags don't produce the key you expected.

How to use

  1. Paste type Xxx struct { ... } declarations. Grouped type ( ... ) blocks and several structs at once are fine.
  2. If a field uses another struct, include that definition too. External package types not in the input (such as decimal.Decimal) become null.
  3. There are no options: the first struct not referenced by another type is the top-level JSON, so put the one you want first or leave out unrelated structs.
  4. Copy the result into curl -d, a Postman body or an httptest-based handler test.

Example

Input (Go struct)
type Base struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
}

type Job struct {
	Base
	Queue      string            `json:"queue"`
	Attempts   int               `json:"attempts,string"`
	Labels     map[string]string `json:"labels,omitempty"`
	TimeoutSec *int              `json:"timeout_sec,omitempty"`
	Token      string            `json:"-"`
	Done       bool
	lastErr    error
}
Output (JSON)
{
  "id": "",
  "created_at": "0001-01-01T00:00:00Z",
  "queue": "",
  "attempts": "0",
  "labels": {
    "key": ""
  },
  "timeout_sec": 0,
  "Done": false
}

The embedded Base contributes id and created_at directly to Job, and Attempts, tagged with ,string, becomes the string "0" instead of a number. Token (tag -) and the unexported lastErr are dropped, while the untagged Done keeps its Go field name as the key. time.Time shows Go's zero value, 0001-01-01T00:00:00Z.

Supported features

  • Uses the json:"name" tag as the key, falling back to the exact field name when there is no tag.
  • Skips json:"-" fields and unexported lowercase fields; json:"-," keeps the field under the literal key -.
  • With ,string, numeric and boolean fields are wrapped as strings like "0" and "false".
  • Untagged embedded structs are flattened into the parent, outer fields winning on name clashes; a tagged embedded struct becomes a nested object under that name.
  • Pointers (*int, *Profile) are filled with the pointed-to type, and defined types such as type Status string follow their underlying type.
  • []byte becomes a Base64 (empty) string, map[int]T uses a "0" key, time.Duration is the nanosecond integer 0, and interface{}/any are null.
  • Self-referencing structs such as Children []Node stop at an empty array. Anonymous nested struct fields are supported.

Use cases

Request bodies for handler tests

Paste the struct you bind with c.ShouldBindJSON(&req), generate the body, and call the endpoint through httptest.NewRequest or curl. Since keys come straight from the tags, binding mismatches are less likely.

Finding tag mistakes

Mixed json:"user_id" and json:"userId" tags, or a forgotten tag that leaks an upper-case UserID key, are obvious at a glance in the output.

Sharing a schema with clients in other languages

Give frontend or Python consumers the JSON from your Go response struct; they can turn it back into models with tools like JSON → TypeScript or JSON → Python.

Notes and limitations

  • omitempty fields are always shown in the sample; real marshaling drops them when they hold the zero value.
  • A nil pointer marshals as null, but the sample shows the populated case.
  • Types with a custom MarshalJSON() and the actual contents of json.RawMessage cannot be known and are not reflected.
  • Newer options such as Go 1.24's omitzero and encoding/json/v2 behavior are not covered.

FAQ

What key does a field without a tag get?

encoding/json uses the exported field name verbatim, so Done bool becomes "Done". Decoding in Go matches case-insensitively, but clients in other languages don't, so explicit tags are safer.

Why is time.Time set to year 0001?

Go's zero time.Time is 0001-01-01 00:00:00 UTC, which marshals in RFC 3339 as 0001-01-01T00:00:00Z. That's why it differs from the 1970 dates on the other → JSON pages.

When is json:",string" useful?

Mostly for large int64 IDs that JavaScript can't represent exactly, so they travel as strings. The sample shows "0", making it clear to clients that they will receive a string.

I want the opposite: Go structs from JSON.

Use the JSON → Go struct page. Feeding its output back into this page is a quick way to check that the round trip keeps the original keys.