Tools · Go

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

no signup · runs entirely in your browser · ⌘V works anywhere on this page

## 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

{"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"` }

[{"id":1,"note":"x"},{"id":2}]package main type Order []OrderItem type OrderItem struct { ID int `json:"id"` Note *string `json:"note,omitempty"` }

{"created_at": "2026-04-21T14:32:08Z"}package main import "time" type Order struct { CreatedAt time.Time `json:"created_at"` }

{"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.

clean-order-example.json → Go, as Convert writes it — 7 structs · 34 fields · json tags · 1.4 kb

```
package main

import "time"

type CleanOrderExample struct {
	OrderID   string    `json:"order_id"`
	CreatedAt time.Time `json:"created_at"`
	Status    string    `json:"status"`
	Customer  Customer  `json:"customer"`
	Items     []Item    `json:"items"`
	Shipping  Shipping  `json:"shipping"`
	Totals    Totals    `json:"totals"`
…
```

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

## Behind this page

## Try it on the file that broke your afternoon.

free · no signup

---

Canonical: https://unstringify.com/tools/json-to-go-struct
