JSON Patch (RFC 6902)
Apply an RFC 6902 JSON Patch to a document.
Overview
The JSON Patch tool applies an RFC 6902 patch document to a JSON target and shows the result. Each operation in the patch — add, remove, replace, move, copy, test — references a node by JSON Pointer (RFC 6901) and either mutates or asserts the document.
It's the standard way to express incremental changes to a JSON resource over the wire, used by Kubernetes, the Microsoft Graph API, and any REST endpoint that accepts application/json-patch+json. Backend developers building APIs or testing patch semantics reach for a json patch tester to validate a patch before sending it to production.
How it works
The patch is a JSON array of operation objects. Each object has an op field (add, remove, replace, move, copy, test), a path JSON Pointer, and either a value (for add/replace/test) or a from (for move/copy). The tool applies the operations in order, atomically — if any step fails (including a test whose expected value doesn't match), the whole patch is rejected.
JSON Pointer paths use / separators with ~0 for literal ~ and ~1 for literal /. The path - at the end of an array means "append". Adding a key that already exists is a replace; replacing a missing key is an error per the spec.
Examples
Target:
{ "name": "Alice", "tags": ["admin"] }
Patch:
[
{ "op": "replace", "path": "/name", "value": "Alicia" },
{ "op": "add", "path": "/tags/-", "value": "ops" },
{ "op": "add", "path": "/age", "value": 30 }
]
Result:
{ "name": "Alicia", "tags": ["admin", "ops"], "age": 30 }
Patch:
[
{ "op": "test", "path": "/age", "value": 30 },
{ "op": "remove", "path": "/age" }
]
FAQ
What's the difference between JSON Patch and JSON Merge Patch?
JSON Patch (RFC 6902) is an operation list and can express deletions and array insertions precisely. JSON Merge Patch (RFC 7396) is a JSON document where null means "delete this key" and any other value replaces; it's simpler but less expressive.
Does the test op fail safely?
Yes — if a test operation doesn't match, the patch stops and the target document is left untouched. This is how you implement optimistic concurrency in patch-based APIs.
Can I generate a patch from two documents?
Yes — switch the JSON diff tool to "JSON Patch" output mode. It produces a valid RFC 6902 patch that transforms the left document into the right.