Indent:
Source JSON 0 B
Ready
Patch (RFC 6902) 0 B
Ready
Result
Result will appear here...
Features

RFC 6902 compliant, bidirectional

📋 RFC 6902 compliance

JSONLab implements the standard six operations: add, remove, replace, move, copy, and test. Patches generated here are interoperable with any RFC 6902 library.

🔁 Bidirectional

Two modes in one tool: apply a patch to a base document, or generate a patch by diffing two JSON values. Switch between them with the tab switcher at the top.

📍 JSON Pointer paths

All paths use JSON Pointer syntax (/users/0/name). Special characters are properly escaped (~0 for ~, ~1 for /) so any path can be addressed.

🧪 Test operation

Use test ops to verify that a value at a path matches the expected value before applying subsequent operations. Build atomic conditional patches safely.

🚦 Clear error reporting

If any operation fails (path not found, type mismatch, test failure), the tool stops and reports the exact failure. Operations applied before the failure remain in the result.

⚡ Fast in-browser execution

Patches apply in linear time relative to the number of operations and the size of the document. Multi-megabyte JSON with hundreds of ops completes in milliseconds.

FAQ

JSON Patch — common questions

What is RFC 6902 JSON Patch?

RFC 6902 is a standard format for describing changes to a JSON document, published by the IETF in 2013. A JSON Patch is a JSON array of operations, where each operation has an op field (one of add, remove, replace, move, copy, or test), a path field (a JSON Pointer string), and (for some ops) a value or from field.

Patches are applied sequentially: each operation is performed in order, with the result of one feeding into the next. If any operation fails, the entire patch fails (though operations already applied remain in effect on the working copy).

JSON Patch is commonly used with the HTTP PATCH method for partial updates of API resources — instead of sending the full resource, the client sends a small list of changes.

What is JSON Pointer syntax?

JSON Pointer is a string format defined in RFC 6901 for referencing a specific value inside a JSON document. It's a slash-separated list of keys, starting with a slash: /users/0/name points to document.users[0].name.

Array indices are written as plain numbers (/0, /1). The special character ~ is escaped as ~0 and / within a key is escaped as ~1, so a key like a/b becomes /a~1b in pointer form.

The empty string "" refers to the entire document (the root). JSONLab handles all of these cases automatically when generating and applying patches.

What is the test operation for?

The test operation checks that the value at a given path equals the specified value. If the values don't match (using deep equality), the entire patch fails with an error. This enables atomic conditional updates.

For example, you might write [{"op":"test","path":"/version","value":3},{"op":"replace","path":"/name","value":"new"}] to update the name only if the version is still 3 — protecting against lost updates when multiple clients are editing the same document.

Tests can also be used for debugging: sprinkle them through a patch to verify assumptions about intermediate state. JSONLab reports the exact path where any test fails.

How are errors handled?

JSONLab applies operations sequentially. If any operation fails — invalid path, type conflict, array index out of range, or a failed test — the tool stops and reports the failing operation along with the error message. Operations applied before the failure remain in effect on the result.

This matches the behavior of most RFC 6902 implementations: patches are not transactional by default. For atomic behavior, wrap your patch in a test at the start to verify the document hasn't changed, and apply the patch only if the test passes.

The error message includes the operation index and the JSON Pointer where the failure occurred, making it easy to identify the problematic operation.

How does JSON Patch compare to JSON Merge Patch?

JSON Merge Patch (RFC 7396) is a simpler alternative: you provide a partial JSON object whose fields overwrite the corresponding fields in the target. Fields set to null in the merge patch are removed from the target. It's concise and human-readable, but limited — it can't address array indices, can't move values between paths, and treats null ambiguously.

JSON Patch (RFC 6902) is more expressive: it can target specific array indices, move values between paths, copy values, and conditionally test. The trade-off is verbosity — even a simple field update requires a JSON object with three fields.

Use Merge Patch for simple object updates where arrays don't matter. Use JSON Patch when you need precise control over arrays, conditional updates, or atomic operations. JSONLab supports both: this tool for JSON Patch, and the JSON Diff tool can generate Merge Patches via its structural view.