JSON API Payload Patterns

Reusable JSON payload shapes for APIs: envelopes, pagination, errors, metadata, partial updates, and event-style messages.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Response envelopes
Single resource response
{
  "data": {
    "id": "usr_123",
    "name": "Ada",
    "email": "ada@example.com"
  }
}

# A simple object response with nested data.

Paginated list response
{
  "data": [
    { "id": 1, "name": "Ada" },
    { "id": 2, "name": "Linus" }
  ],
  "meta": {
    "page": 1,
    "page_size": 20,
    "total": 250
  }
}

# A list payload with page metadata.

Cursor-based response
{
  "data": [
    { "id": "evt_1" },
    { "id": "evt_2" }
  ],
  "meta": {
    "next_cursor": "eyJpZCI6ImV2dF8yIn0="
  }
}

# Include a cursor token for the next page.

## Errors, events, and partial updates
Structured error payload
{
  "error": {
    "code": "USER_NOT_FOUND",
    "message": "No user exists for the supplied id.",
    "details": {
      "id": "usr_999"
    }
  }
}

# Return a machine-readable error code and human-readable message.

Partial update payload
{
  "display_name": "Ada Lovelace",
  "timezone": "America/Los_Angeles"
}

# Send only the fields that should change.

Event-style message payload
{
  "event": "user.created",
  "occurred_at": "2026-03-27T17:00:00Z",
  "data": {
    "id": "usr_123",
    "email": "ada@example.com"
  }
}

# A message with event type, timestamp, and nested data.

Recommended next

No recommendations yet.