json-patch/json-patch2

Add a merge operator

Opened this issue · 0 comments

The current RFC lacks compatibility when using multiple json patches, most glaringly the inability to patch patched json - for patches that are made by independent authors and thus are not aware of the others patches. Take the following initial situation:

Source file

{ "firstname": "Mad", "lastname": "Max" }

Patch 1

{ "op": "add", "path": "/attributes", "value": { "age": 15 } }

Patch 2

{ "op": "add", "path": "/attributes", "value": { "continent": "Europe" } }

As per RFC6902, the add op replaces the value if it exists, and thus we get

{ "firstname": "Mad", "lastname": "Max", "attributes": { "continent": "Europe" } }

which means we have lost the age property. I propose a merge op that merges the value if it is an object.