in reply to Create JSON patch

I googled for you and found http://jsonpatch.com/

What's wrong with http://github.com/zigorou/perl-json-patch ?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Create JSON patch
by Anonymous Monk on Oct 06, 2017 at 19:16 UTC
    That module applies patches but does not create them.
      Can this even be easily done ? ? ?

      I see a lot of operations which indicate strongly, that there is more than one possible solution.

      • Add
      • Remove
      • Replace
      • Copy
      • Move

      So which algorithm should be used to decide, if an element has to be "moved" instead of being "replaced" ...

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        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". ;-)