JSON Patch Generator — Create RFC 6902 Patch Operations
Understanding the Basics
JSON Patch (RFC 6902) is a format for describing changes to a JSON document as a sequence of operations. Unlike sending a complete replacement document, a JSON Patch document specifies only what changed — add, remove, replace, move, copy, or test — making it ideal for partial updates in REST APIs. When you HTTP PATCH an endpoint, best practice is to send a JSON Patch array rather than a full JSON body, reducing bandwidth and making the intent of the change explicit. Each operation in the array has three fields: "op" (the operation type), "path" (a JSON Pointer like /users/0/email pointing to the location), and "value" (the new value for add/replace operations). The "test" operation is particularly powerful — it asserts a value before applying changes, enabling optimistic concurrency control: if the document has changed since you last read it, the test fails and the entire patch is rejected atomically. JSON Patch is supported natively in .NET, Spring Boot, and many API frameworks. Our generator automatically computes the minimal patch to transform one JSON document into another, outputting a ready-to-use RFC 6902 patch array.
How to Use the Tool
- Paste the original JSON document into the left editor.
- Paste the target (desired state) JSON document into the right editor.
- Click "Generate Patch" — the tool computes the minimal set of operations to transform original into target.
- Review the generated JSON Patch array with op, path, and value for each change.
- Copy the patch array for use as an HTTP PATCH request body or store it for version control purposes.
Key Features & Specifications
- Generates minimal RFC 6902 JSON Patch arrays automatically from two JSON documents
- Supports all six patch operations: add, remove, replace, move, copy, and test
- Uses JSON Pointer (RFC 6901) paths for precise location addressing
- Applies the patch to the original in a preview panel to confirm correctness
- Bidirectional patch visualization showing the before/after state for each operation
Frequently Asked Questions (FAQ)
- Q:What is the difference between JSON Patch and JSON Merge Patch?
- RFC 6902 JSON Patch uses explicit operations (add, remove, replace) with JSON Pointer paths, enabling precise changes and atomic test-and-set. RFC 7396 JSON Merge Patch is simpler — you send a partial object and keys with null values are deleted — but it cannot remove array elements, add to the middle of arrays, or perform test operations.
- Q:How does the "test" operation work?
- A test operation {"op":"test","path":"/version","value":3} asserts that the document's /version field currently equals 3 before any other operations execute. If the assertion fails, the entire patch is rejected without applying any changes, providing optimistic locking semantics.
- Q:Can JSON Patch add items to an existing array?
- Yes. Use op: "add" with path ending in "/-" to append to the end of an array, or use a specific index like "/items/2" to insert at that position. Use op: "remove" with the index path to delete a specific array element.