JSON to Go Struct
Convert JSON to Go structs with json tags, aligned like gofmt. Optional fields become pointers with omitempty; timestamps can become time.Time.
*string tells “missing or null” apart from “”
Off uses int
RFC 3339 strings like 2026-03-14T09:26:53Z
package main
import "time"
type Root struct {
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
IsActive bool `json:"isActive"`
Rating float64 `json:"rating"`
CreatedAt time.Time `json:"createdAt"`
AvatarURL any `json:"avatarUrl"`
Tags []string `json:"tags"`
Address Address `json:"address"`
Orders []Order `json:"orders"`
}
type Address struct {
Street string `json:"street"`
City string `json:"city"`
ZipCode string `json:"zipCode"`
}
type Order struct {
OrderID string `json:"orderId"`
Total float64 `json:"total"`
Items int64 `json:"items"`
Shipped bool `json:"shipped"`
Coupon *string `json:"coupon,omitempty"`
}
Arrays of objects are merged: a key missing from some items becomes optional, null makes a field nullable, and identical shapes share one type. Paste several examples in an array for the most accurate types.
About this tool
Paste JSON and get Go structs you can drop into your code. Field names follow Go conventions with initialisms such as ID, URL and API, every field has its json tag, and the output is aligned exactly as gofmt would format it. Arrays of objects are merged, so a key missing from some items becomes optional (a pointer with omitempty), null makes a field nullable, and integers and decimals are told apart even for values like 10.0. Nested objects become their own named types, identical shapes share one type, and objects keyed by IDs become maps. Options choose the package name, pointers, omitempty, int or int64 and time.Time for RFC 3339 timestamps. You can switch to Rust, C#, Python or Kotlin from the same page.
How to convert JSON to Go structs
Generate Go types from a JSON sample.
- 1
Paste JSON
Paste a JSON object, or an array of examples for the most accurate types.
- 2
Choose options
Set the root type name, package, pointers, omitempty and time.Time.
- 3
Copy the code
Copy the structs or download types.go.