JSON struct tags

Annotations like `json:"next_cursor"` that tell encoding/json what to call a field and whether to omit it. Only exported fields are encoded, omitempty drops zero values, and a nil slice encodes as null while an empty one encodes as [].

Minimal example

go
type Page struct {
	Items      []Restaurant `json:"items"`
	NextCursor string       `json:"next_cursor"`
}

Learn this concept

Lesson 2.8 · JSON HTTP handlers in Go

Used in exercises

Exercise 2.10 · GET /v1/restaurants with a cursor Exercise 2.12 · GET /v1/restaurants/{id}/menu in five queries Exercise 2.14 · POST /v1/menu/price: price a configured item