Go to JSON Converter

Paste a Go struct plus a composite literal. Get clean JSON back.

Input

Output

Paste your Go code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

You have a Go struct with json:"..." tags and a composite literal somewhere (order := Order{...}) and you need the JSON shape that encoding/json would produce. Paste both into the left editor and hit Convert. The tool reads the tags, applies omitempty and - rules, handles pointer nils, and hands you JSON that matches what json.MarshalIndent would emit, so you can skip the round-trip through go run.

It follows the real Go marshalling semantics, not naive substitution. Exported field names are renamed by the first part of the json tag. omitempty drops zero values (empty string, 0, false, nil, empty slice/map). A tag of - removes the field. Embedded (anonymous) struct fields are promoted the way encoding/json promotes them. time.Time comes out as an RFC 3339 string per RFC 8259-compatible formatting, and byte slices ([]byte) are base64-encoded.

Numeric types follow Go rules: float64 keeps its precision, int/int64 stay as numbers, and a nil pointer becomes JSON null. Slices become JSON arrays; a nil slice also becomes null (not []), which matches the default Marshal behaviour. map[string]V becomes a JSON object. Paste several structs in one go: each instance ends up as a top-level entry.

How to use it

Three steps. Works for a tiny struct or a full types.go file.

1

Paste your Go (or try the sample)

Paste the type declarations together with a composite literal such as order := Order{...}; the literal is what supplies the values. Embedded structs, pointer fields and several types in one paste are fine. Load Sample loads an Order with json tags, a time.Time, an omitempty postal code and a nil *float64 discount.

Keep your package line and imports: the parser ignores them. Struct tags, method receivers, and comments are all fine. For reference, the encoding/json.Marshal docs spell out every rule this tool follows. The Go source repo is worth a look if you hit an edge case.

2

Hit Convert

Click the green Convert button. Your Go travels to the backend, which applies the struct tags to the literal and sends back JSON while a "Converting..." overlay waits on top of the panels.

3

Copy the JSON

The right panel fills with JSON ready for an API request, a test table, a config file, or a fixture you load with os.ReadFile.

When this actually comes in handy

HTTP handler request/response samples

You have a request or response struct for a net/http or gin handler. Paste it with a literal and get a JSON body you can send with curl or paste into Postman.

Table-driven test fixtures

Convert a struct instance from a table test into a standalone JSON file for golden-file testing or external tooling.

Kubernetes CRDs and manifests

Turn a Go struct representing a custom resource or controller payload into the JSON form used by kubectl apply or the Kubernetes API.

Kafka / NATS / gRPC-gateway messages

Serialize a Go message struct into JSON for producer testing, sample payloads, or documentation without spinning up the full pipeline.

Common questions

Does it honour the json struct tag?

Yes. The first tag value renames the field, omitempty drops zero values, and - excludes the field entirely. This matches the rules documented in the encoding/json Marshal reference.

How are time.Time and []byte handled?

time.Time is formatted as RFC 3339 (e.g. "2026-03-14T10:30:00Z"), matching time.Time.MarshalJSON. []byte is base64-encoded as a JSON string, which is what the standard library does by default.

What about nil pointers and nil slices?

A nil pointer becomes JSON null. A nil slice also becomes null (not []): matching Go's default. If you want an empty array, initialize the slice with []T{}.

Are embedded (anonymous) struct fields promoted?

Yes. Fields on an embedded struct get flattened into the outer object, unless the embedded struct has its own json tag: same rules encoding/json applies.

Can I paste a whole file with multiple structs?

Yes. Each struct type that has a value in the paste gets an entry, and nested types are written inline wherever a field uses them. A type with no literal has no values to show, so add one for every type you want to see.

Is my code stored anywhere?

The code is posted to the backend for this request and is not stored. Config structs often get pasted with real DSNs or tokens in their literals, so swap those first.

Other tools you may need

When an API payload needs to become a Go struct, or the frontend needs TypeScript types for the same data, start with the first and sixth links; the rest check and reshape the JSON: