JSON Merge Patch

Apply a JSON Merge Patch (RFC 7396) — the application/merge-patch+json body of an HTTP PATCH. A merge patch is a partial document overlaid on the target: a member present in the patch replaces (or, for nested objects, is merged into) the target, a member whose value is null removes that key, and a patch that is anything other than an object (an array, scalar, or null) replaces the target wholesale.

It is the simpler companion to the operation-based JSON Patch (b.jsonPatch): merge patch can't reorder arrays or express a value that is genuinely null, but it reads like the resource you want. merge returns a new document and never mutates its inputs, and writes member keys as literal own properties (a "__proto__" key cannot reach the prototype).

b.jsonMergePatch.merge(target, patch) #

stable0.12.59soc2

Apply a JSON Merge Patch (RFC 7396) to a target document and return the result. When the patch is an object, each member overlays the target — a null value deletes the key, a nested object merges recursively, and any other value replaces; when the patch is itself an array, scalar, or null, it replaces the whole target. The inputs are never mutated (the work happens on a deep copy) and member keys are written as literal own properties, so a "__proto__" member cannot alter any prototype.

b.jsonMergePatch.merge({ a: "b", c: { d: "e" } }, { a: "z", c: { d: null, f: 1 } });
// → { a: "z", c: { f: 1 } }

Last updated 2026-08-08T16:39:49.652Z by seeder.