json-patch / json-patch2

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

Could we add oldvalue to the JSON patch standard? #30

Open mmachenry opened 1 year ago

mmachenry commented 1 year ago

I believe the addition of an oldvalue field to the replace and remove operations for JSON patch could greatly increase the usability and adoption because with this simple change it allows JSON patch to act as both an edit history as well as enables patches to be reverted instead of only applied.

I'm using JSON patch for documenting user updates to objects in my database. This is a DynamoDB accessible through a REST API so JSON Patch is a pretty natural standard for this. I store every patch along with the current version and users can see the edit history which I display to the web app front end.

I do, however, in my application need to extend the patch standard with one extra feature, which is the old value of any remove or replace operation. This gives me the two aforementioned features that I need.

For starters, the user can now see, when I expose the JSON patch data to the the front end, what the edit history is. Without the oldvalue a user only knows what a new value has become and not what it used to be. Adding old value now gives the whole picture of the edit, which is necessary when creating a user edit history for a database JSON document.

Next, I would like to be able to take my edit history along with the current value in the DB and revert the changes of an edit. In order to do this we need to understand what the old value is to reverse the process but adding this to just replace and remove gives us just that.

I'm wondering if there's any chance you'd be interested in augmenting the existing standard in this way.

Thank you very much for the consideration and great work on the existing standard.