Home → JSON Patch RFC 6902 Online
Apply JSON Patch operations: add, remove, replace, move, copy, test.
Apply JSON Patch operations: add, remove, replace, move, copy, test. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.
JSON Patch is a standard for expressing incremental changes to a JSON document using a sequence of typed operations.
Six operations cover all possible changes: add inserts new values, remove deletes them, replace updates existing values, move relocates values, copy duplicates values, and test asserts a value equals an expected value before the patch proceeds.
A patch document is a JSON array of operation objects. Each object has an "op" field (the operation name), a "path" field (a JSON Pointer to the target location), and optionally "value" (the new value) and "from" (source path for move/copy).
Two different RFC standards address partial JSON updates — each has distinct strengths.
Use JSON Patch when you need precise control: updating a specific array element by index, moving values between paths, or using the test operation as a precondition check before making changes.
JSON Merge Patch (RFC 7396) is simpler: send just the fields you want to change, and null means delete. It is easier to read and write for simple updates, but cannot express all changes that JSON Patch can.
JSON Patch defines a way to describe changes to a JSON document using a sequence of operations. It's used in REST APIs (HTTP PATCH), version control, and document collaboration.
// Original Document
{"name": "Alice", "age": 30, "roles": ["user"]}
// Patch Document (array of operations)
[
{"op": "replace", "path": "/name", "value": "Bob"},
{"op": "add", "path": "/email", "value": "bob@example.com"},
{"op": "remove", "path": "/age"},
{"op": "add", "path": "/roles/-", "value": "admin"},
{"op": "copy", "path": "/backup", "from": "/name"},
{"op": "move", "path": "/fullName", "from": "/name"},
{"op": "test", "path": "/fullName", "value": "Bob"}
]
// Result
{"fullName": "Bob", "email": "bob@example.com", "roles": ["user","admin"], "backup": "Bob"}
| Operation | path | value/from | Description |
|---|---|---|---|
| add | /path | value | Add a value; use /array/- to append |
| remove | /path | — | Remove the value at path |
| replace | /path | value | Replace existing value (must exist) |
| move | /path | from: /src | Move value from src to path |
| copy | /path | from: /src | Copy value from src to path |
| test | /path | value | Assert value equals; fail patch if not |
// npm install fast-json-patch
import jsonpatch from "fast-json-patch";
const original = {name: "Alice", age: 30};
const patch = [
{op: "replace", path: "/name", value: "Bob"},
{op: "add", path: "/email", value: "bob@example.com"}
];
const result = jsonpatch.applyPatch(original, patch).newDocument;
console.log(result); // {name:"Bob", age:30, email:"bob@example.com"}
RFC 6902 defines six operations. Each operation is a JSON object in the patch array with an op field specifying the action. All operations are applied atomically — if any fails, none are applied.
| Operation | Description | Example |
|---|---|---|
| add | Add a value at a path | {"op":"add","path":"/name","value":"Alice"} |
| remove | Remove a value | {"op":"remove","path":"/temp"} |
| replace | Replace a value | {"op":"replace","path":"/age","value":31} |
| move | Move a value to new path | {"op":"move","from":"/a","path":"/b"} |
| copy | Copy a value to new path | {"op":"copy","from":"/a","path":"/b"} |
| test | Assert a value matches | {"op":"test","path":"/status","value":"active"} |
// Original document
{"name": "Alice", "age": 30, "status": "pending", "temp": true}
// JSON Patch
[
{"op": "replace", "path": "/age", "value": 31},
{"op": "replace", "path": "/status", "value": "active"},
{"op": "remove", "path": "/temp"},
{"op": "add", "path": "/role", "value": "admin"},
{"op": "test", "path": "/name", "value": "Alice"}
]
// Result
{"name": "Alice", "age": 31, "status": "active", "role": "admin"}
RFC 6902 (JSON Patch) and RFC 7396 (JSON Merge Patch) are both standards for updating JSON documents, but they have very different formats and capabilities.
| Aspect | JSON Patch (RFC 6902) | JSON Merge Patch (RFC 7396) |
|---|---|---|
| Format | Array of operation objects | Partial JSON document |
| Operations | 6 (add, remove, replace, move, copy, test) | Implicit (present=set, null=delete) |
| Precision | Exact path targeting | Key-based only |
| Array support | Index-based or append (-) | Replace entire array |
| Delete field | {"op":"remove","path":"/field"} | {"field": null} |
| Complexity | Higher | Lower |
| Use case | Fine-grained updates | Simple partial updates |
Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff