Home → JSON Patch RFC 6902 Online

JSON Patch RFC 6902 Online

Apply JSON Patch operations: add, remove, replace, move, copy, test.

About This Tool

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.

What JSON Patch Is (RFC 6902)

JSON Patch is a standard for expressing incremental changes to a JSON document using a sequence of typed operations.

JSON Patch 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.

Applying Patches

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).

JSON Patch vs JSON Merge Patch

Two different RFC standards address partial JSON updates — each has distinct strengths.

When to Use JSON Patch

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.

When to Use JSON Merge Patch

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.

Frequently Asked Questions

What is JSON Patch?+
JSON Patch (RFC 6902) is a standard format for describing changes to a JSON document as a sequence of operations. Instead of sending the entire updated document, you send a patch — an array of operation objects that describe exactly what to add, remove, replace, move, or copy. It is commonly used in REST APIs for partial updates via the HTTP PATCH method.
What operations does JSON Patch support?+
JSON Patch supports six operations: add (insert a new value), remove (delete a value), replace (change an existing value), move (move a value from one path to another), copy (copy a value from one path to another), and test (verify a value equals an expected value — failing the entire patch if it does not).
What is a JSON Pointer and how does it relate to JSON Patch?+
JSON Pointer (RFC 6901) is the path syntax used in JSON Patch operations. A JSON Pointer like /user/address/city navigates through the JSON structure using forward slashes. JSON Patch uses JSON Pointers in the 'path' and 'from' fields to identify which part of the document to operate on.
Is JSON Patch atomic?+
Yes. If any operation in a patch array fails — a test operation fails or a remove targets a non-existent path — the entire patch is rejected and no changes are applied. This all-or-nothing behavior makes JSON Patch safe for critical updates where partial application would leave data in an inconsistent state.

JSON Patch (RFC 6902) Reference

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.

All 6 Patch Operations

// 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"}

JSON Patch Operations Reference

Operationpathvalue/fromDescription
add/pathvalueAdd a value; use /array/- to append
remove/pathRemove the value at path
replace/pathvalueReplace existing value (must exist)
move/pathfrom: /srcMove value from src to path
copy/pathfrom: /srcCopy value from src to path
test/pathvalueAssert value equals; fail patch if not

JSON Patch in JavaScript

// 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"}

JSON Patch Operations Reference

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
addAdd a value at a path{"op":"add","path":"/name","value":"Alice"}
removeRemove a value{"op":"remove","path":"/temp"}
replaceReplace a value{"op":"replace","path":"/age","value":31}
moveMove a value to new path{"op":"move","from":"/a","path":"/b"}
copyCopy a value to new path{"op":"copy","from":"/a","path":"/b"}
testAssert 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"}

JSON Patch vs JSON Merge Patch

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)
FormatArray of operation objectsPartial JSON document
Operations6 (add, remove, replace, move, copy, test)Implicit (present=set, null=delete)
PrecisionExact path targetingKey-based only
Array supportIndex-based or append (-)Replace entire array
Delete field{"op":"remove","path":"/field"}{"field": null}
ComplexityHigherLower
Use caseFine-grained updatesSimple partial updates

Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff