go ahead... be a heretic | |
PerlMonks |
Re^4: Create JSON patchby afoken (Chancellor) |
on Oct 07, 2017 at 13:20 UTC ( [id://1200892]=note: print w/replies, xml ) | Need Help?? |
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
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|