Developer

JSON to Go Struct

Generate Go struct definitions from JSON with proper tags.

All tools

JSON

Go

type Meta struct {
	Email string `json:"email"`
}

type Root struct {
	Id int64 `json:"id"`
	UserName string `json:"user_name"`
	IsActive bool `json:"is_active"`
	Scores []int64 `json:"scores"`
	Meta Meta `json:"meta"`
}

Frequently asked questions

Why are JSON keys converted to PascalCase in Go?
Go requires struct fields to be exported (start with a capital letter) to be visible to encoding/json. The original JSON key is preserved through a `json:"..."` struct tag so marshalling still uses the lowercase name.
How are nullable JSON values handled in Go structs?
A null field maps to a pointer type like *string or *int so the zero value is distinguishable from missing. For numeric fields you can also use sql.NullInt64 or a similar wrapper depending on the package.
What happens to a JSON number that does not fit in a Go int?
Large or fractional numbers should be typed as int64 or float64; otherwise unmarshalling will fail or lose precision. Use json.Number for round-trip safety when the source might exceed 53 bits.