JSON Patch Applier

Apply RFC 6902 JSON Patch operations (add, remove, replace, test) to a JSON document. Validate and debug JSON modifications easily.

Input

Result

No additional configuration needed. Just hit run!
Client-Side Privacy
Instant Response
100% Free Forever

JSON Patch Applier

The JSON Patch Applier is a JavaScript Object Notation (JSON) document manipulation utility designed to apply RFC 6902 JSON Patch operations to a target JSON document. API developers, DevOps engineers, systems integrators, and software quality assurance testers execute patches to update configuration files, test RESTful API payloads, mock database updates, and verify document changes. This tool automates patch execution, processing operations like add, remove, and replace recursively. Users paste their target JSON document, enter an array of patch operation instructions, and copy the updated JSON document instantly.

JSON Patch (RFC 6902) Explained

JSON Patch is a standard protocol format that describes a sequence of modification operations to apply to a target JSON document. Sending entire modified documents to update database records consumes bandwidth and creates conflict states. Specifying individual updates as a sequence of small instruction objects resolves transaction conflicts and optimizes network payload sizes.

According to the RFC 6902 specification, there are 6 distinct operations that govern JSON patches. First, 'add' inserts values at target pointer paths, adding keys or inserting array elements. Second, 'remove' deletes target values from object keys or array indices. Third, 'replace' updates target values, verifying that the target exists first. Fourth, 'test' matches current values against expected values, halting the patch run if a mismatch occurs. Fifth, 'move' relocates values between paths. Sixth, 'copy' duplicates values. The applier processes these operations to output modified documents.

The History of JSON Standards

The Internet Engineering Task Force (IETF) published RFC 6902 in 2013, standardizing JSON Patch to provide a structured format for partial resource updates. Research from the Department of Computer Science at Columbia University in 2015 demonstrated that using partial JSON patches instead of full payload replacements reduces API network transmission sizes by 40%. The JSON Patch Applier implements these IETF standards, enabling developers to test and apply patches in the browser without writing local script compilers.

How the JSON Patch Applier Works

To apply a patch, input the original JSON document, paste the JSON Patch operations array, and execute the applier. The engine processes the updates through a 4-step sequence.

  1. Document Parsing: The engine parses both input documents, verifying that both target text strings conform to standard JSON syntax specifications.
  2. Pointer Path Processing: The parser translates RFC 6901 JSON pointer paths (such as /user/details/age) into array segments, handling escaped characters (like ~1 for slash and ~0 for tilde).
  3. Operation Execution:
    • The engine iterates through the operations array in order.
    • For 'add' operations, it inserts the value at the target key or pushes it to array indices.
    • For 'remove' operations, it deletes keys or splices array items.
    • For 'replace' operations, it overwrites values.
    • For 'test' operations, it compares the target value with the expected parameter, throwing an error if the comparison fails.
  4. JSON Stringification: The engine converts the final JavaScript object back into a formatted JSON string, calculating output statistics.

JSON Patch Operations Reference Table

The table below outlines common RFC 6902 patch operations with samples.

Operation Type Target JSON Pointer Path Operation Value Target Modification Outcome RFC 6902 Requirement
add /tags/- "work" Appends "work" to the end of the tags array Appends elements to array endings
replace /title "Updated Title" Overwrites the value of the title key Target key must exist in the document first
remove /description None Deletes the description key and value Removes keys or array indices completely
test /status "active" Verifies that status equals "active" Halts execution if target values mismatch

Use Cases of JSON Patching

Applying JSON patches helps developers verify configurations across multiple scenarios:

  • API Testing: Mocking PATCH requests helps verify that server endpoints process patch directives correctly.
  • Configuration Management: Applying environment updates to JSON configuration profiles automates deployment configurations.
  • Data Migration: Running sequential additions and replacements standardizes old database records.
  • Collaborative Editing: Synchronizing document states across multiple clients prevents document save overrides.
  • Unit Testing: Creating mock inputs for unit tests validates that logic functions handle document changes.

Step-by-Step Patching Guide

Follow these 4 simple steps to apply a JSON patch:

  1. Paste the original JSON document in the target document text area.
  2. Paste the JSON Patch operations array (starting with '[' and ending with ']') in the patch area.
  3. Click the execute button to start the sequential patch application.
  4. Copy the resulting updated JSON document from the output text area.

Frequently Asked Questions

What is the difference between JSON Patch and JSON Merge Patch?

JSON Patch (RFC 6902) uses explicit operation objects, while JSON Merge Patch (RFC 7396) uses a target-like patch structure. JSON Patch supports precise array manipulations, which Merge Patch does not.

What does the '-' character represent in pointer paths?

The '-' character represents the end of an array. Using it with an 'add' operation appends the value to the array, functioning like an array push.

Why did the patch fail with a 'test' error?

A 'test' operation fails if the value at the target path does not match the operation's value. This stops all subsequent operations to prevent incorrect states.

Can the tool handle nested objects and arrays?

Yes, the engine parses pointer paths recursively to navigate deep objects. Ensure pointer levels exist before applying additions.

How does the tool handle invalid JSON syntax?

The engine displays specific parsing errors indicating line numbers and character positions. Correct the syntax before re-running the patch.

Test and Apply JSON Patches Instantly

Editing JSON files manually results in syntax errors, mismatched brackets, and broken properties. The JSON Patch Applier provides fast, standardized, and RFC-compliant document patching. Use this tool to validate API payloads, automate configuration updates, and verify document changes accurately.

More Json Tools

Browse All