API Engineering

JSON API Format: Request Payloads, Headers, and Response Schemas

Deep dive into JSON API structures: envelopes vs raw arrays, standard error schemas, pagination meta keys, and Content-Type negotiation.

By Cometflow API Engineering Team • Updated 2026-10-06

JavaScript Object Notation (JSON) is the dominant data serialization format for web APIs. However, inconsistent JSON structures cause friction for frontend developers. Establishing clean response conventions transforms an average API into an extraordinary developer experience.

1. Standard JSON Response Envelope Pattern

Wrapping payloads in a predictable top-level envelope allows client SDKs and TypeScript generics to inspect data and pagination metadata without guessing:

{
  "success": true,
  "data": [
    { "id": "bk_101", "title": "TypeScript Handbook", "publishedAt": "2026-03-14T10:00:00Z" },
    { "id": "bk_102", "title": "Designing Data-Intensive Applications", "publishedAt": "2026-04-02T08:30:00Z" }
  ],
  "meta": {
    "page": 1,
    "perPage": 20,
    "totalCount": 84,
    "totalPages": 5
  }
}

2. Data Type Serialization Rules

  • ISO-8601 UTC Timestamps: Always format dates and timestamps in UTC ISO-8601 format (2026-10-19T14:30:00Z) rather than ambiguous locale strings or raw millisecond numbers.
  • Monetary Amounts in Minor Units: Represent currency amounts as integer cents ("amountCents": 1999) or decimal strings ("19.99") to avoid IEEE 754 floating-point rounding bugs (0.1 + 0.2 === 0.30000000000000004).
  • Strict Content Negotiation: Always serve JSON with Content-Type: application/json; charset=utf-8 and validate incoming payloads at the boundary using Zod or JSON Schema.