๐Ÿ”’ Runs in your browser โ€” nothing is uploadedโœ“ Free, no signup

JSON to Go Struct Converter

Paste JSON to generate Go structs with json tags. Nested objects become their own structs, optional fields get omitempty, and common initialisms like ID and URL are capitalised the Go way.

Loading...

0 characters

Go structs

Loading...

When should you use the JSON to Go?

  • Decoding an API response in a Go service
  • Creating types for a JSON config file
  • Writing Go clients for third-party APIs

How to use the JSON to Go

  1. 1

    Paste JSON

    Paste a sample object or array โ€” the more complete the sample, the better the types.

  2. 2

    Name the struct

    Change Root to something meaningful like User or Response.

  3. 3

    Choose options

    Keep omitempty on optional fields and pointers for nullable fields, or turn them off.

  4. 4

    Copy into your project

    Copy the structs or download them as types.go.

Examples

Array items with an optional field

JSON

{
  "id": 1,
  "orders": [
    { "total": 9.5 },
    { "total": 20, "coupon": "SAVE" }
  ]
}

Go

type Root struct {
	ID     int64   `json:"id"`
	Orders []Order `json:"orders"`
}

type Order struct {
	Total  float64 `json:"total"`
	Coupon string  `json:"coupon,omitempty"`
}

Common errors and how to fix them

A field is interface{}
The sample had only null for that field, or mixed types. Paste a sample where the field has a real value, or set the type by hand.
Numbers became float64
If any item has a decimal (like 15.5), the field becomes float64. Whole numbers everywhere give int64.
Related tools:ย JSON to TypeScript ยท JSON to Python ยท JSON to Java

More from JSON Tools

Free tools that run in your browser โ€” no signup, nothing uploaded.

JSON to Go FAQ

JSON keys are converted to exported PascalCase Go names, and common initialisms are uppercased โ€” user_id becomes UserID and avatarUrl becomes AvatarURL. The original key is kept in the json tag.

When a key is missing from some objects in an array, or is null. Untick the option if you don't want it.

Whole numbers become int64 and decimals become float64. If a field has both, it becomes float64.

Each nested object becomes its own named struct, which makes the code easier to read and reuse.

A pointer like *string lets you tell the difference between a missing or null value and an empty string.

No. Everything runs in your browser, so your JSON never leaves your device.