Skip to main content
Back to Blog

JSON Patch Explained: How RFC 6902 Works in Practice

2026-04-12 8 min read

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
addAdd a value at path (or replace array item)op, path, value
removeRemove the value at pathop, path
replaceReplace an existing valueop, path, value
moveMove a value from one path to anotherop, from, path
copyCopy a value from one path to anotherop, from, path
testAssert a value before applying further opsop, 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.

Example patch array
[
  { "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.