JSON Patch Applier

Apply a minimal RFC 6902-style add/remove/replace patch with RFC 6901 pointers to a JSON document.

Description

Apply add, remove, and replace JSON Patch operations to a JSON document using JSON Pointer paths.

The JSON Patch applier updates serialized JSON without manually editing nested objects and arrays. It is useful for testing API payload changes, replaying a small change set, and verifying the patch emitted by the companion JSON diff tool.1, 2

When to use JSON Patch Applier

  • Apply deterministic changes to an API fixture
  • Test JSON Pointer paths against nested arrays and objects
  • Replay a patch generated by the JSON diff tool

How the calculation works

Both fields are parsed as JSON. Operations run sequentially, so each one sees the result of the previous operation. Paths use JSON Pointer escaping: `~1` represents `/` and `~0` represents `~`. Array add operations insert at an index, while `-` appends.1, 2

Interpreting the result

`result` is compact serialized JSON and `appliedOpCount` is the number of completed operations. The tool rejects a missing path, an invalid array index, malformed JSON, or an unsupported operation instead of silently changing a different location.

Important limitations

  • This focused implementation supports `add`, `remove`, and `replace`; RFC 6902 `move`, `copy`, and `test` are not implemented.
  • Removing the entire document through the empty root pointer is intentionally rejected.
  • Patch order is significant and operations are not automatically reordered.

References

  1. RFC 6902: JavaScript Object Notation (JSON) Patch — RFC Editor

  2. RFC 6901: JavaScript Object Notation (JSON) Pointer — RFC Editor

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies