JSON to Go

Skip to editor
Explorer
Open Files

No files open

0 files open

jsoneditor.io v2

{
  "orderId": "ord_8F2K1",
  "status": "shipped",
  "customer": {
    "id": 4182,
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "items": [
    {
      "sku": "KB-104",
      "name": "Mechanical keyboard",
      "qty": 1,
      "price": 89.99
    },
    {
      "sku": "MS-220",
      "name": "Wireless mouse",
      "qty": 2,
      "price": 24.5
    }
  ],
  "total": 138.99,
  "paid": true,
  "notes": null
}
JSONUTF-8
Spaces: 2

How do I convert JSON to a Go struct?

To turn JSON into Go structs, paste a sample above, open Convert and press Go. The structs open in a new tab, ready for encoding/json.

Field names are exported and follow Go's initialisms, so id becomes ID and avatarUrl becomes AvatarURL, while json tags keep the original keys. Whole numbers become int64 and decimals float64, keys missing from some items get omitempty, values that are sometimes null become pointers and nested objects become their own named structs.

  1. Paste a sample JSON response into the editor.
  2. Open Convert and press Go.
  3. Copy the structs from the new tab.

Example

JSON
{
  "orderId": "ord_8F2K1",
  "status": "shipped",
  "customer": {
    "id": 4182,
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "items": [
    {
      "sku": "KB-104",
      "name": "Mechanical keyboard",
      "qty": 1,
      "price": 89.99
    },
    {
      "sku": "MS-220",
      "name": "Wireless mouse",
      "qty": 2,
      "price": 24.5
    }
  ],
  "total": 138.99,
  "paid": true,
  "notes": null
}
Go
type Root struct {
	OrderID  string   `json:"orderId"`
	Status   string   `json:"status"`
	Customer Customer `json:"customer"`
	Items    []Item   `json:"items"`
	Total    float64  `json:"total"`
	Paid     bool     `json:"paid"`
	Notes    any      `json:"notes"`
}

type Customer struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Item struct {
	Sku   string  `json:"sku"`
	Name  string  `json:"name"`
	Qty   int64   `json:"qty"`
	Price float64 `json:"price"`
}

Questions people ask

How accurate is the generated Go?

As accurate as your sample. The generator only knows what it can see, so a field that can be null but never is in your sample won't be marked nullable. Paste a response with a few varied items for the best result.

Why is a field typed as any?

That field was null in every sample, or held different kinds of value, so there was nothing to pick a type from. Paste a sample where it has a real value and you'll get a proper type.

Is my data uploaded anywhere?

No, this runs entirely in your browser, so nothing you paste is sent to a server. The only feature that sends data anywhere is the optional AI assistant, and only when you actually ask it something.