JSON Patch
Apply an RFC 6902 JSON Patch — an ordered list of operations (add, remove, replace, move, copy, test) — to a JSON document, the standard payload of an HTTP PATCH with Content-Type: application/json-patch+json. Each operation's path (and from) is an RFC 6901 JSON Pointer, resolved through b.jsonPointer.
apply is atomic: operations run against a deep copy, so if any operation fails — an out-of-range index, a missing source, or a failed test — the original document is returned untouched and a typed error is thrown. The test operation compares structurally (object key order is irrelevant).
b.jsonPatch.apply(doc, operations) #
Apply an RFC 6902 JSON Patch (an array of operation objects) to a JSON document and return the patched result. The operations run against a deep copy, so a failure at any step — an unknown op, a missing path / value / from, an out-of-range array index, or a failed test — throws a typed error and leaves the input doc unmodified. The test operation compares values structurally.
b.jsonPatch.apply({ a: 1 }, [
{ op: "add", path: "/b", value: 2 },
{ op: "remove", path: "/a" },
]);
// → { b: 2 }
Last updated 2026-08-08T16:39:49.652Z by seeder.