A well-designed request or response payload favors explicit objects over bare scalars, additive optional fields over required ones, enums over binary booleans, and one consistent top-level shape across endpoints—because once a client parses your JSON, every structural choice becomes a promise you can only extend, never rewrite, without breaking someone in production.
Quick answer: Wrap collections in an envelope with room for metadata, cap nesting at two or three levels, use enums instead of booleans for anything that might grow a third state, model scalars as objects when they might need units or context later, and never repurpose a field's meaning—add a new one instead.
Payload shape is one of the few API decisions you effectively make once. A wrong endpoint name gets an alias; a wrong auth scheme gets a migration path. But a payload shape lives inside thousands of client integrations the moment it ships, and reshaping it later means a breaking change, a version bump, or years of dual-writing old and new fields. That's the discipline covered in depth in our complete guide to API product design—this piece goes deep on one slice of it: the JSON itself.
Envelope or Bare: Choosing Your Top-Level Response Shape
Choose an enveloped response—a top-level wrapper like { "data": ..., "meta": ... }—whenever you expect to attach pagination, rate-limit, or warning metadata over the endpoint's life. Choose a bare response, where the resource is returned directly, only for simple, single-resource endpoints unlikely to need sibling metadata beyond HTTP headers.
The envelope debate isn't cosmetic—it's about where metadata lives when you inevitably need it. The JSON:API specification formalizes the enveloped approach: every response carries data, and reserves meta, included, and errors as siblings, so a team can add cursor-based pagination info to meta without touching data at all.
Stripe took the opposite path for single resources—its responses return the object directly, with an internal object field identifying the type ("object": "charge")—but still envelopes list endpoints with object: "list" and a data array, because collections almost always need metadata that a bare array has nowhere to hold. Stripe has kept that same core object shape for well over a decade of dated API versions, which is the kind of longevity a payload decision like this one is really being made for.
Avoid a bare array at the root. A response that's just
[ {...}, {...} ]has no top-level object to later attach anext_cursorortotal_countto, without breaking every client that assumed the response root was an array.
| Aspect | Enveloped response | Bare response |
|---|---|---|
| Top-level shape | { "data": {...}, "meta": {...} } | The resource itself: { "id": "...", ... } |
| Adding pagination or rate-limit info later | Additive—new sibling key under the existing envelope | Requires HTTP headers, or a breaking change to the root shape |
| Client parsing | One extra .data unwrap on every call | Slightly lighter for simple, single-resource calls |
| Real-world precedent | JSON:API (data, meta, included, errors) | Stripe's single-resource responses (bare object plus an object type field) |
| Best fit | Collections, and any API expecting frequent metadata growth | Single-resource CRUD endpoints prioritizing a lean payload |
In practice, most mature APIs land on a hybrid: bare-ish single resources, always-enveloped collections. Whichever you choose, pick one shape and apply it uniformly—a codebase where half the endpoints envelope and half don't forces every client to special-case parsing per endpoint, which is worse than either choice applied consistently.
This is exactly the kind of structural call that belongs in the written contract before anyone starts implementing it, which is why specifying the API contract is one of the concrete jobs a technical PM owns rather than something left to whichever engineer builds the first endpoint.
Nesting Depth: How Deep Before a Payload Becomes a Liability
Keep nested objects to two or three levels deep in most REST payloads: one level for the resource itself, a second for a clearly-owned sub-object (like shipping.address), and rarely a third for something that sub-object owns (shipping.address.geo.lat). Beyond that, client code degenerates into long optional-chaining lookups, and you lose any obvious place to add a new field without picking a new home for it.
Nesting depth is really a proxy for a resource-modeling question: is this nested thing genuinely part of the parent resource, or is it a resource of its own that deserves its own endpoint and its own identity? Getting that distinction right is the subject of resource modeling around nouns rather than actions—a shipping_address embedded three levels deep because "it's easier for now" is usually a sign the address should be its own addressable resource, linked by ID, not buried.
A nested object that keeps needing its own filters, its own pagination, or its own update endpoint isn't really nested—it's a resource wearing a disguise.
Nesting depth also depends on which style you're building in. GraphQL clients tolerate—and expect—deeper, client-shaped nesting because they request only the fields they need; a REST payload has no such escape hatch and pays the full nesting cost on every call regardless of what the client actually wanted. If your team is still deciding between styles, that tradeoff is one input into the decision framework for choosing REST, RPC, or GraphQL.
| Nesting depth | Typical use | Risk as the API grows |
|---|---|---|
| 1 level (flat) | Simple resources, config-style values | Runs out of room fast; every new grouping forces a rename or a breaking restructure |
| 2–3 levels | Resource plus one or two clearly-owned sub-objects | The range most REST style guides converge on; still easy to extend additively |
| 4+ levels | Deeply composed aggregates, GraphQL-style joins flattened into REST | Client code turns into long optional-chaining spelunking; hard to version one nested piece independently |
A useful gut check: if you can't say, in one sentence, why a field lives three levels deep rather than two, it probably shouldn't.
Enums vs Booleans: Designing for the State You Haven't Named Yet
Use an enum—a named string value like status: "active"—over a boolean like is_active: true for any field where a third state is even plausible in the endpoint's lifetime. A boolean encodes exactly two states and no path to a third without a breaking change or an ambiguous null.
The failure mode is familiar: is_active ships fine until "suspended" or "pending_review" needs representing. At that point you're choosing between three bad options:
- Overload
nullas a third state, even though every existing client already treats it as falsy or throws on it. - Add a second boolean, like
is_suspended, that can combine with the first in invalid ways (bothtrueat once). - Break the field's type entirely, forcing every client to update on your schedule.
An enum sidesteps all three—status just gains a new permitted string value, which is additive by definition.
Google's API Improvement Proposals (AIP-126), which govern enum design across the hundreds of APIs in Google's public Cloud portfolio, recommend every enum reserve a zero value like STATUS_UNSPECIFIED as the default—so an old client reading a brand-new enum value it doesn't recognize degrades to "unspecified" instead of crashing on an unrecognized string. That single convention is what makes enums safely additive rather than just additive in theory.
| Field type | Looks fine today | Where it breaks |
|---|---|---|
Boolean (is_active) | Exactly two states, forever | A third state needs a new field or an overloaded null |
Enum (status: "active") | Same two states today, room for more | New states are additive string values—no schema break |
Boolean pair (is_paid, is_refunded) | Feels more granular than one field | States can combine invalidly (both true); no single authoritative value |
A practical rule: if you're tempted to add a second boolean to disambiguate a first one, that's the signal you needed an enum from the start. Collapse them into one field before either ships.
Reserving Room for Growth: Objects Over Scalars and the Never-Repurpose Rule
Model a scalar as an object the moment it might ever need context, units, or a second related value—price: 1999 becomes price: { "amount": 1999, "currency": "USD" }—because adding a sibling key inside an object is additive, while changing a bare scalar's meaning or type is not. The cost is one extra level of nesting; the payoff is years of headroom.
This is the core insight behind "objects over scalars, growth over minimalism": a bare number, string, or boolean has exactly one dimension, and the day you need a second dimension—a currency, a unit, a confidence score, a source—you're stuck. An object absorbs that new dimension as a sibling key with zero disruption to clients reading the first one.
Common candidates for this treatment:
- Money — always
{ amount, currency }, never a bare number (which decimal precision and currency issues make actively dangerous, not just inflexible). - Durations —
{ value: 30, unit: "days" }rather than a bare integer that silently assumes a unit. - Scores or ratings —
{ value: 4.2, scale: 5, source: "internal" }rather than a bare float that can't later explain where it came from. - Any identifier that might need a second form —
{ id: "usr_123", external_id: "cust_456" }rather than a singleidstring.
Every field on a payload exists to serve some job the calling client is trying to get done—the same lens the complete guide to Jobs to Be Done applies to product decisions generally. A field that can't name the job it serves is usually the one that gets awkwardly repurposed six months later, which brings up the rule that matters most here:
Never repurpose a field. Once a field has shipped with a documented meaning, that meaning is permanent. If requirements change, deprecate the old field (keep returning it, mark it deprecated in the docs) and add a new one with the new meaning. Reusing
statusto mean something subtly different than it meant last year silently breaks every client that read the old semantics correctly.
Repurposing is worse than a breaking change because it doesn't announce itself. A removed field triggers a 404 or a validation error somewhere—loud and debuggable. A repurposed field keeps validating, keeps parsing, and just silently means something different, which is the kind of bug that surfaces as a support ticket weeks later, not a build failure on day one.
A Before/After Redesign: Turning a Brittle Payload Into One That Bends
Here's a plausible first-draft response for an order endpoint—reasonable-looking, and already carrying four of the problems above:
{
"id": "ord_88291",
"total": 129.99,
"is_paid": true,
"is_refunded": false,
"shipping_address": {
"line1": "12 Market St",
"city": "Austin",
"zip": "78701",
"geo": {
"coords": {
"lat": 30.267,
"lng": -97.743
}
}
},
"created": "2026-01-04"
}
Walking it against the rules above turns up four separate problems:
totalis a bare scalar with no currency attached.is_paid/is_refundedis a boolean pair that can't represent "partially refunded" and can combine invalidly.shipping_address.geo.coords.latis four levels deep for two plain numbers.- The response has no envelope, so there's nowhere to add a
warningsarray if the order has a data-quality issue worth flagging.
The redesigned version fixes each issue additively—nothing here removes information, it just gives each value room:
{
"data": {
"id": "ord_88291",
"total": { "amount": 12999, "currency": "USD" },
"status": "paid",
"shipping_address": {
"line1": "12 Market St",
"city": "Austin",
"zip": "78701",
"geo": { "lat": 30.267, "lng": -97.743 }
},
"created_at": "2026-01-04T00:00:00Z"
},
"meta": {
"warnings": []
}
}
status is now a single enum that can grow to "partially_refunded" next quarter without a schema break. total is an object that could later gain a tax_amount sibling. The geo object dropped one needless wrapping level (coords added nothing geo didn't already imply—a reminder that nesting depth cuts both ways; add a level for a reason, not by default). And the envelope means a meta.warnings array, or later a meta.rate_limit, has an obvious home that didn't exist before.
None of these changes broke a client reading the original fields correctly—if the old fields were deprecated rather than deleted outright, existing integrations would keep working while new ones adopt the better shape.
Where Prodinja Fits: Reviewing Payload Shape as Part of the Contract
Every rule above is easy to state and easy to skip under deadline pressure, which is why payload shape needs to be reviewed as a deliberate part of the API contract—not discovered by an engineer improvising field names while implementing. Prodinja's API Designing tool lets you define request and response bodies explicitly, endpoint by endpoint, so the envelope choice, the nesting depth, and the enum-versus-boolean call for each field get made and reviewed before an endpoint ships rather than reverse-engineered from whatever the first implementation happened to return.
That review moment matters because the developer experience of an API isn't one interaction—it's a multi-year relationship, not unlike the arc mapped in our guide to the customer journey: a client integrates once, then has to survive every version bump you make after. A payload reviewed for growth room up front is what keeps that relationship additive instead of forcing a migration guide onto every integrator two years in.
Key Takeaways
- Pick one top-level shape—enveloped or bare—and apply it uniformly; collections almost always benefit from an envelope since they need somewhere to hold pagination and rate-limit metadata.
- Cap nesting at two or three levels in REST payloads; anything deeper is usually a sign a nested object deserves to be its own addressable resource.
- Prefer enums over booleans for any field where a third state is plausible, and reserve a default/unspecified value so unrecognized future values degrade safely.
- Model scalars as objects (money, durations, scores, identifiers) the moment they might need a second dimension like units or currency—an object absorbs new context as an additive sibling key.
- Never repurpose a field's meaning. Deprecate and add a new field instead; a repurposed field fails silently, while a removed one at least fails loudly.
- Review payload shape as part of the API contract, before implementation starts, not as whatever the first working version happened to return.
Frequently Asked Questions
Should API responses always use an envelope?
Not always—use an envelope for collections and any endpoint likely to need metadata (pagination, warnings, rate limits), but a bare single-resource response is fine when metadata needs are unlikely. The one shape to avoid is a bare array at the root, which has nowhere to attach pagination info later.
Is it better to use enums or booleans in API design?
Enums are safer whenever a third state is even plausible, because adding a new enum value is additive while a boolean forces an overloaded null or a second, potentially conflicting boolean. Reserve booleans for fields that are genuinely, permanently binary, like is_deleted on a soft-delete flag.
How deep should JSON nesting go in a REST API?
Two to three levels is the practical ceiling for most REST payloads—one for the resource, one or two for clearly-owned sub-objects. Deeper nesting usually signals that a nested object should be its own resource with its own endpoint and identifier instead.
What does it mean to design a payload for additive changes?
It means every anticipated future change—a new field, a new enum value, a new metadata key—can be added as a sibling without altering or removing what's already there. Objects over scalars, enums with an unspecified default, and an envelope with room for meta are the three biggest levers for making that true.
Can I add new fields to an API response without breaking clients?
Yes, as long as clients are built (and instructed) to ignore unrecognized fields—a discipline that echoes Jon Postel's robustness principle, first written into internet protocol specifications in the early 1980s: be liberal in what you accept, conservative in what you promise. New optional fields are safe; changing an existing field's type or meaning is not.