JSON Patch Explained: How RFC 6902 Works in Practice
JSON Patch (RFC 6902) defines a standard way to describe changes to a JSON document as an array of operations. Instead of sending the entire updated resource, you send only what changed. Use our JSON Patch tool to generate and apply patches in your browser.
The Six Operations
| Operation | Description | Required fields |
|---|---|---|
| add | Add a value at path (or replace array item) | op, path, value |
| remove | Remove the value at path | op, path |
| replace | Replace an existing value | op, path, value |
| move | Move a value from one path to another | op, from, path |
| copy | Copy a value from one path to another | op, from, path |
| test | Assert a value before applying further ops | op, path, value |
JSON Pointer Syntax
Paths use JSON Pointer (RFC 6901). The root document is "/" and keys are separated by "/". Array indices use numeric positions. To reference a key containing "/" or "~", escape as "~1" or "~0" respectively. Example: "/users/0/name" refers to the name of the first user.
[
{ "op": "replace", "path": "/user/name", "value": "Alice" },
{ "op": "add", "path": "/user/role", "value": "admin" },
{ "op": "remove", "path": "/user/legacy_id" },
{ "op": "test", "path": "/version", "value": 3 }
] Using test for Optimistic Concurrency
The test operation verifies a value before applying other operations. If the test fails, the entire patch is rejected atomically. This is the JSON Patch equivalent of optimistic locking: assert the current state before mutating it, preventing overwriting concurrent changes.
When to Use JSON Patch vs Full Updates
Use JSON Patch when your API supports PATCH semantics and you want to avoid accidentally overwriting fields that were changed by another client between your GET and PATCH. Full PUT updates are simpler but require sending the entire resource and risk losing concurrent edits. For visual side-by-side comparison without patch generation, use the JSON Diff tool.
Generate and apply JSON Patch operations online
Use Diff mode to compute a patch from two JSON documents, or Apply mode to execute an RFC 6902 patch array.