What is JSON Patch?
JSON Patch is an IETF standard specified in RFC 6902. It defines a precise structure for describing updates made to a target JSON document.
Instead of sending an entire updated document over the network using an HTTP PUT request, a client sends a JSON Patch array via an HTTP PATCH request (Content-Type: application/json-patch+json). This reduces bandwidth consumption, avoids race conditions, and makes partial updates explicit.
If you only need to inspect raw line-by-line differences visually, you can use our JSON Diff tool. However, when building programmatic API request bodies, generating an RFC 6902 patch is the industry-standard approach.
Why Generate a JSON Patch?
Generating a patch is often much more efficient than handling full documents, especially in professional web development:
- Reduced Bandwidth: If you have a 1MB JSON file but only changed one word, a JSON Patch might only be 100 bytes. This saves data for both the user and the server.
- API Efficiency: Many modern REST APIs (like those used in WordPress or enterprise apps) support the
PATCHHTTP method. Using a standard patch ensures compatibility. - Precision: It eliminates the risk of accidentally overwriting data. You are explicitly telling the system: “Change this specific field,” rather than “Replace the whole object.”
- Atomic Updates: It allows you to perform multiple changes (add this, delete that, update this) in a single, organized sequence.
Features of This JSON Patch Generator
This tool was built to be a lightweight, high-performance addition to your site:
- Standard Compliant: Uses the
fast-json-patchlibrary to ensure every patch follows the RFC 6902 protocol perfectly. - Ultra-Responsive: The CSS Grid layout ensures the “Original” and “Modified” boxes sit side-by-side on desktops but stack vertically on mobile for easy typing.
- Clean UI: Uses a minimalist design with consistent, centered buttons that look professional on any WordPress theme.
- Smart Validation: It detects if your JSON code is broken (like missing a comma or bracket) and tells you exactly which side needs fixing.
- User-Friendly Copying: Includes a “Copy” button that provides instant feedback (“Copied!”) so users know their action worked.
How to Use the JSON Patch Generator
Generating a patch array takes only a few seconds:
- Paste Original Data: Enter your base JSON document into the Original JSON pane on the left. If you need to clean or format your structure beforehand, run it through our JSON Editor or JSON Viewer.
- Paste Modified Data: Enter your target updated JSON document into the Modified JSON pane on the right.
- Generate Patch: Click the Generate Patch button.
- Copy Output: The tool instantly analyzes structural and value differences, generating the corresponding RFC 6902 compliant JSON array in the output panel.
Example Input & Output
Original JSON:
JSON
{
"name": "John",
"age": 30
}
Modified JSON:
JSON
{
"name": "John Doe",
"age": 30,
"city": "Surat"
}
Generated JSON Patch Output:
JSON
[
{ "op": "replace", "path": "/name", "value": "John Doe" },
{ "op": "add", "path": "/city", "value": "Surat" }
]
JSON Patch (RFC 6902) vs. JSON Merge Patch (RFC 7396)
Understanding when to use JSON Patch versus JSON Merge Patch is critical for API architecture:
| Feature | JSON Patch (RFC 6902) | JSON Merge Patch (RFC 7396) |
| Format | Array of operation objects | Single partial JSON object |
| Array Edits | Can insert, remove, or update specific array indexes | Replaces entire arrays |
| Null Values | Can explicitly set a key to null | Treats null as a command to delete the key |
| Atomic Updates | Yes (all-or-nothing execution) | No |
| Supported Verbs | add, remove, replace, move, copy, test | Implicit merge logic |
Frequently Asked Questions
1. What is the difference between JSON Patch and JSON Diff?
JSON Diff identifies and highlights textual or structural differences between two JSON structures for human review. JSON Patch creates a machine-readable JSON array of RFC 6902 instructions designed to be processed programmatically by web servers and APIs.
2. Is this JSON Patch Generator fully compliant with RFC 6902?
Yes. The generated patch payload strictly adheres to the standard IETF RFC 6902 specification and uses valid RFC 6901 JSON Pointer syntax for all paths.
3. How does JSON Pointer handle array indexes?
Array targets use zero-based indexing in paths (e.g., /users/0 targets the first element in the array). To target the end of an array for appending items, the special dash syntax /users/- is used.
4. Can I send a JSON Patch directly in an HTTP PATCH request?
Yes. Set your HTTP request header to Content-Type: application/json-patch+json and pass the generated JSON Patch array directly in the request body.
5. What happens if one operation in a patch fails?
According to RFC 6902 rules, JSON Patch application must be atomic. If any operation fails (such as a missing path or failed test operation), none of the modifications should be applied to the target resource.
6. How does JSON Patch set a key value to null versus deleting it?
To set a field to null, use the replace or add operation with "value": null. To delete the field entirely from the document, use the remove operation without specifying a value.
7. Is my JSON data processed securely?
Yes. All processing happens locally inside your web browser using client-side JavaScript. Your private JSON data is never transmitted to external servers.
8. How are key paths formatted if JSON keys contain slashes or tildes?
RFC 6901 JSON Pointer requires special character escaping: ~ is encoded as ~0, and / is encoded as ~1. For example, a key named a/b is represented in the path as /a~1b.
9. Can JSON Patch rename a field key directly?
While there is no dedicated rename operator in RFC 6902, renaming is efficiently performed using the move operation by specifying the current path in from and the desired path in path.
10. Why is JSON Patch better than JSON Merge Patch for arrays?
JSON Merge Patch cannot modify specific elements within an array—it requires sending the entire updated array. JSON Patch allows you to target specific indexes to insert, remove, or replace individual array items.