download

How do you evolve a JSON response without breaking live clients?

Backend~10 minReviewed 3 Dec 2026Free · No sign-in

Question

GET /v1/orders/{id} currently returns {"id": "ord_7", "price": 19.99} to web users plus iOS v2.1 and Android v3.0 apps already in the wild. Product wants to replace float price with "total": {"amount_cents": 1999, "currency": "USD"}.

  1. Why does replacing price in place break older mobile builds even if your web app ships at the same time?
  2. Which JSON response changes are backwards-compatible versus breaking?
  3. Design a safe rollout for total inside /v1/orders/{id}, and explain when to send RFC 9745 Deprecation and RFC 8594 Sunset headers on a retiring /v1/ resource.
Show hints (3)
  1. "CLIENTS UPGRADE SLOWLY"

    You control your web deploy, not phones. Mobile versions stay installed for months and crash if price disappears or changes type.

  2. "EXPAND THEN CONTRACT"

    Add total alongside price first so both old and new clients work. Remove price only after telemetry shows zero old callers.

  3. "RETIRING V1 RESOURCE"

    Mark price deprecated in OpenAPI while evolving /v1/. Send RFC 9745 Deprecation and RFC 8594 Sunset headers on /v1/orders/{id} only when retiring that URI for /v2/.

Show checked explanation

Never rename, remove, or retype a live JSON field in one deploy because older mobile apps stay active for months. Evolve /v1/ with expand-and-contract: add total while keeping price, mark price deprecated in OpenAPI, and drop it only once telemetry shows zero legacy callers. Use RFC 9745 Deprecation and RFC 8594 Sunset headers when retiring the /v1/ URI itself for /v2/.

"SOLUTION · PYTHON"
from email.utils import formatdate


def serialize_order(oid, cents, currency, legacy=True):
    body = {"id": oid, "total": {"amount_cents": cents, "currency": currency}}
    if legacy:
        body["price"] = round(cents / 100, 2)
    return body


def sunset_headers(dep_ts, sunset_ts, doc_url):
    return {"Deprecation": f"@{dep_ts}",
            "Sunset": formatdate(sunset_ts, usegmt=True),
            "Link": f'<{doc_url}>; rel="deprecation"'}


print("expand:", serialize_order("ord_7", 1999, "USD", legacy=True))
print("contract:", serialize_order("ord_7", 1999, "USD", legacy=False))
print("v1_retire:", sunset_headers(1798761600, 1814400000, "/docs/orders-v2"))
"OUTPUT"
expand: {'id': 'ord_7', 'total': {'amount_cents': 1999, 'currency': 'USD'}, 'price': 19.99}
contract: {'id': 'ord_7', 'total': {'amount_cents': 1999, 'currency': 'USD'}}
v1_retire: {'Deprecation': '@1798761600', 'Sunset': 'Thu, 01 Jul 2027 00:00:00 GMT', 'Link': '</docs/orders-v2>; rel="deprecation"'}

Ran the dual-shape serializer and RFC 9745/8594 header helper on CPython 3.12.10 against simulated old/new clients and a local http.server. Checked by an editor other than the author.

Walkthrough

A backend deploy updates all servers in minutes, while mobile users keep old app binaries for months. Changing a response field in place breaks every client still expecting price as a JSON number.

Judge every JSON change by whether an unmodified live client still parses and acts on it:

Response changeBreaking?Safe alternative
Add optional total objectNoShip directly in v1
Rename price to totalYesServe both during overlap
Change 19.99 to "19.99"YesAdd new field with new type
Allow price to be nullYesKeep non-null default or add new field
Add new closed enum valueOften yesVersion enum or negotiate client capability

Roll out field changes inside /v1/orders/{id} in four stages:

  1. Expand: Ship serialize_order(..., legacy=True) so responses carry both price (19.99) and total ({"amount_cents": 1999, "currency": "USD"}). Old iOS v2.1 and Android v3.0 read price and ignore total. Migrated iOS v2.2 and Android v3.1 read total.
  2. Deprecate the field and migrate: Mark price with deprecated: true in OpenAPI 3.1 and update web and mobile apps to read total. Do not send Sunset while /v1/orders/{id} remains operational.
  3. Measure drain: Log X-Client-Version or User-Agent to track how many callers still run v2.1 or v3.0. Prompt remaining mobile users to upgrade.
  4. Contract or retire /v1/: Drop price (legacy=False) only once legacy callers reach zero. If partners pin /v1/ longer, keep /v1/orders/{id} intact and launch /v2/orders/{id} with total only. When retiring the /v1/ URI itself, emit RFC 9745 Deprecation: @1798761600 (2027-01-01), RFC 8594 Sunset: Thu, 01 Jul 2027 00:00:00 GMT, and Link: </docs/orders-v2>; rel="deprecation". Both headers apply to the URI, and RFC 8594 reserves Sunset for resources that will stop responding.

Common mistakes

  • Renaming price to total in one release because the web frontend updated in the same PR. Older mobile and partner clients break immediately.
  • Making a previously non-null response field nullable. Typed Swift, Kotlin, and TypeScript clients throw decode errors on null.
  • Dropping a deprecated field on a calendar date without checking client-version metrics first, silently breaking active partner integrations.
  • Changing a field's units (dollars 19.99 to cents 1999) under the same key name price. Clients keep parsing cleanly while showing 100x wrong prices.

Follow-up questions

  • "When should you bump to /v2/ instead of evolving /v1/ with expand-and-contract?" Stay on /v1/ for additive fields and small renames you can overlap cleanly. Introduce /v2/ when core resource shapes, pagination rules, auth models, or error semantics change so much that carrying both inside /v1/ would confuse callers.
  • "Why can adding a new value to a response enum break older clients?" Many compiled clients map JSON strings to a closed enum with no fallback case. Returning a brand-new status like "partially_refunded" crashes decoding unless older apps already have an unknown branch.
  • "What makes a request schema change backwards-compatible versus breaking?" Request compatibility is the mirror image of responses. Making an existing request field optional or widening accepted enum values is safe. Adding a new required field or tightening a length limit breaks existing callers.

What a strong answer covers

Classifies additive vs breaking JSON changes and explains why mobile clients force overlap windows. Separates in-place field expand-and-contract (OpenAPI deprecated: true + telemetry) from resource-level /v1/ retirement using RFC 9745 Deprecation and RFC 8594 Sunset.

Open in interactive practice deck →

Original OfferVibe question. OpenAPI 3.1.1 Specification · RFC 9745 Deprecation Header · RFC 8594 Sunset Header.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.