JSON to Go struct
Paste JSON and get Go structs with json tags — exported names from your keys, one struct per nested object, time.Time where a string is an RFC 3339 date. gofmt-clean.
What you get
- Writes the API-response sample as 7 structs · 34 fields · json tags
- Exports every field with Go’s spelling — order_id → OrderID, sku → SKU, loyalty_tier → LoyaltyTier — and keeps the JSON key in the tag
- time.Time where every value seen is an RFC 3339 date-time (and imports "time" for it), int for numbers written whole, float64 for the rest — 149.00 is float64 — []Item for a list
- A pointer where the sample has null (*string), a pointer with ,omitempty where a key is missing from some elements
- Aligns names, types and tags in columns the way gofmt does, the root struct first, one struct per nested object
What it will not do
- Write encoding/json boilerplate, methods, or a package name other than main.
- Guess a null’s type beyond string: a field that is only ever null is *string, said so here.
- Send your text anywhere. The page is static and the engine runs in this tab — open the network panel and watch it stay empty.
What you get
- An object → a struct with json tags, named from the file
{"order_id": "o1", "sku": "A", "loyalty_tier": "gold"}package main type Order struct { OrderID string `json:"order_id"` SKU string `json:"sku"` LoyaltyTier string `json:"loyalty_tier"` }- A key missing in some items → a pointer, omitempty
[{"id":1,"note":"x"},{"id":2}]package main type Order []OrderItem type OrderItem struct { ID int `json:"id"` Note *string `json:"note,omitempty"` }- An RFC 3339 string → time.Time, with its import
{"created_at": "2026-04-21T14:32:08Z"}package main import "time" type Order struct { CreatedAt time.Time `json:"created_at"` }- A number written whole → int, written with a point → float64, null → *string
{"qty": 2, "total": 149.00, "line2": null}package main type Order struct { Qty int `json:"qty"` Total float64 `json:"total"` Line2 *string `json:"line2"` }149.00 is float64: Go’s decoder would refuse it into an int, and the source said decimal.
The sample
What the first sample opens — a real file, not an illustration written for this page.
in VS Code
Convert, then Go struct — the structs land in a new .go editor beside the JSON.
Questions
Why OrderID and SKU, not OrderId and Sku?
Go’s own convention, the one golint enforces: an initialism stays upper-case in an exported name. The json tag keeps the key exactly as your API writes it, so decoding is unaffected.
Why is a null field a pointer?
A *string decodes null to nil and a value to a pointer, which is how Go tells the two apart; a plain string would read null as "". A key missing from some elements gets ,omitempty as well.
What happens when a field is only ever null?
It is *string. A lone null says nothing about the value, so this is the one guess the structs make — and they guess string.