json-patch / json-patch2

A possibile revision to the JSON-Patch format
44 stars 0 forks source link

Add a merge operator #31

Open tyronx opened 1 year ago

tyronx commented 1 year ago

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.