liveBook · Manning

JSON Merge Patch

As explained in The Design of Web APIs, Second Edition

JSON Merge Patch is a standardized JSON-based format for describing modifications to a target JSON document through a partial replacement structure.

JSON Merge Patch is a standardized, widely adopted format for partial updates: a consumer sends only the resource properties it wants to modify through PATCH instead of replacing the complete resource with PUT. Its partial structure keeps update requests smaller and more intuitive. section 5.3.4 section 13.5.6

Updating a product

A PATCH /products/{productReference} request can use a ProductModification model containing only the changed properties. The model may restrict updates further: for example, a supplier defined during creation can remain non-modifiable. Consumers therefore avoid resending the complete product required by a total replacement. section 5.3.4

Choose JSON Merge Patch with these trade-offs in mind:

  • Prefer it over JSON Patch when usability, common adoption, and straightforward OpenAPI or JSON Schema documentation matter. section 13.5.6 section 14.2.5
  • Treat array updates carefully: JSON Merge Patch sends the entire affected array, while JSON Patch can address one element efficiently. section 13.5.6
  • Use dedicated operations when arrays contain many frequently changed elements rather than optimizing every update with JSON Patch. section 13.5.6
  • Support both formats through content negotiation when consumers require different update representations. section 13.5.6 section 13.9

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains partial resource models, update restrictions, array trade-offs, media types, and alternatives, but not implementation code.
Examples
Uses product modification models and an account-owner address-array update to contrast partial and sequential patch requests.
What it assumes
Assumes familiarity with HTTP resources and PUT, while introducing partial update models and format selection.
What you can do after
Apply it via PATCH to design smaller, consumer-friendly partial-update requests and evaluate when JSON Patch is justified.
How it connects
Connects JSON Merge Patch to PATCH, PUT, JSON Patch, content negotiation, OpenAPI, JSON Schema, and dedicated operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.