in reply to Re^3: Create JSON patch
in thread Create JSON patch
So which algorithm should be used to decide, if an element has to be "moved" instead of being "replaced"
My guess is that the JSON patch format was meant to do updates on large JSON files (or resources, in HTTP context) without having to transfer the entire file all the time. So one very likely scenario would be a mobile application or a javascript-based application running in a browser that wants to modify the data structure and then post back the changes to a server. In that case, the application knows quite well if it has removed, replaced, added, copied or moved something.
Giving arbitary JSON files, all a program could do is guessing. A simple brute-force algorithm roughly based on diff would probably use only add and remove. In a second step, one could change every sequence of Remove and Add for the same node with Replace. Remove and Add for an identical subtree, but different nodes could be replaced with Move. Copy needs more work, but it should not be impossible.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Create JSON patch (updated)
by LanX (Saint) on Oct 07, 2017 at 13:29 UTC | |
by afoken (Chancellor) on Oct 07, 2017 at 14:39 UTC | |
by LanX (Saint) on Oct 07, 2017 at 14:56 UTC | |
by afoken (Chancellor) on Oct 07, 2017 at 18:44 UTC | |
by LanX (Saint) on Oct 07, 2017 at 19:42 UTC |