Go to JSON Converter
Paste a Go struct plus a composite literal. Get clean JSON back.
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 <code>types.go</code> file.
Paste your Go (or try the sample)
Drop the struct definitions plus a composite literal (order := Order{...}) into the left editor. A single struct, multiple structs with embedded fields, or a package-level declaration — all fine. Click Load Sample for a realistic starting point.
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.
Hit Convert
Click the green Convert button. The tool parses the struct definitions, resolves the composite literal, applies tag rules, and produces indented JSON.
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 <code>net/http</code> or <code>gin</code> 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 <code>kubectl apply</code> 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. Every struct type with an instance in the paste ends up as its own entry in the JSON. Nested struct types are expanded inline wherever they are used.
Is my code stored anywhere?
Code is sent to the backend to be converted and is not persisted or logged. As with any online tool, give sensitive code a look before pasting.
Other tools you may need
Go to JSON is one piece of the puzzle. Here are the tools that pair well with it: