Delete value in an array with an object
When you have two json docs like these: {"1": [1,{"1":1}]} {"1": [{"1":1}]}
jsondiffpatch gives me: {"1": {"0": [{"1": 1}], "_0" : [1, 0, 0], "_1": [{"1": 1}, 0, 0], "_t": "a"}}
But the library I made to replicate the diff format[1], creates this: {"1": {"_0": [1, 0, 0], "_t": "a"}}
But give the exact same result when you use patch but both are still pretty straight forward, it's just that the other is briefer and more inline with other results; like if you don't have an object.
[1] https://github.com/olafura/json_diff_ex
well, I'm not sure how this works in Elixir (I just found out about it :) ), but the problem that makes jsondiffpatch be suboptimal in that case is, there's no trivial way to determine {"1":1} is the same object as {"1":1} unless they are equal by reference (in which jsondiffpatch will handle it as expected).
So when jsondiffpatch finds 2 objects in the 2 arrays, and they're not equal by ref, it tries to use an option if provided, the objectHash function. if not provided, it just assumes they are 2 different unrelated objects. (that's why the diff is saying "remove both items, and insert this new one".
this can only be solved if you provide an objectHash function to make object comparison possible, for example:
var differ = jsondiffpatch.create({ objectHash: function(obj) {
return obj.id;
}
and If that isn't available either, it will fallback to try to match objects by position.
Nothing of these works in your example (as apparently those objects have no way to match them but to compare the whole object). I'm curious how are you solving that in json_diff_ex?
In other words, how do you know that this object {"1":1} in the 2nd array is the same as the {"1":1} in the first array?