waynetools

Guides · JSON & Config

JSON Patch vs Merge Patch — which one for your API?

RFC 6902 is an operation list; RFC 7386 is "what the result should look like." Same change, both formats, side by side — plus the null trap and the decision table.

RFC 6902 · RFC 7386 Verified 2026-07-11
Direct answer

Use JSON Merge Patch when clients send simple partial updates to object fields and your model has no meaningful nulls. Use JSON Patch when you need array-element updates, real nulls, moves, or the test operation for optimistic concurrency. Merge Patch is what most people mean by "send a PATCH"; JSON Patch is what you graduate to when the edge cases arrive.

§1 · The same change, both formats

Original document: {"name": "Aurora", "status": "active", "config": {"retries": 3}, "tags": ["edge", "beta"]}. We want: status → "paused", retries → 5, drop the whole config.sampleRate idea, and change the first tag.

JSON Patch (RFC 6902) — an ordered operation list

OpMeaning
{"op":"replace", "path":"/status", "value":"paused"}exact field, exact intent
{"op":"replace", "path":"/config/retries", "value":5}nested path, one key only
{"op":"replace", "path":"/tags/0", "value":"ga"}array element BY INDEX — Merge Patch cannot do this
{"op":"test", "path":"/status", "value":"active"}abort atomically if someone changed it first

JSON Merge Patch (RFC 7386) — the shape of the result

PatchEffect
{"status":"paused", "config":{"retries":5}}fields mentioned are set; fields omitted stay
{"owner": null}⚠ null means DELETE the field — not "set to null"
{"tags": ["ga","beta"]}arrays replace WHOLE — there is no per-element edit

§2 · The decision table

NeedMerge PatchJSON Patch
Simple field updatesperfectworks, verbose
Set a field to real nullimpossible (null = delete)yes
Edit one array elementno (whole-array replace)yes, by index
Optimistic concurrencynotest op
Move / copy valuesnoyes
Human-writable by handyespainful
Content typeapplication/merge-patch+jsonapplication/json-patch+json

Generate either format from two JSONs: paste before/after and export an applicable RFC 6902 Patch or RFC 7386 Merge Patch.

Open JSON diff tool →

§3 · The gotchas that reach production

§4 · FAQ

What's the difference in one sentence?

JSON Patch says what to do (ops on paths, ordered, atomic); Merge Patch says what it should look like (partial result document).

How do I set null with Merge Patch?

You can't — null means delete. Real nulls in your model are the classic forcing function toward JSON Patch.

How do I append to an array with JSON Patch?

{"op":"add","path":"/tags/-","value":"new"} — the - index means "end of array".

Which content types do I use?

application/json-patch+json for RFC 6902, application/merge-patch+json for RFC 7386 — and dispatch on them server-side.

§5 · Related tools