JSON8 icon indicating copy to clipboard operation
JSON8 copied to clipboard

Use add/remove for array diffs

Open yannsartori opened this issue 4 years ago • 5 comments

This change would utilize add/remove for the patch operation rather than just a replace.

yannsartori avatar Sep 30 '21 00:09 yannsartori

Please explain why you would want to do that?

sonnyp avatar Oct 07 '21 22:10 sonnyp

If one would like to see a more refined diff for their list. If I have ['a', 'b', 'c'] becoming ['a', 'c', 'd'], rather than just seeing in the diff "value is now ['a', 'c', 'd']", I could see "'b' was removed and 'd' appended".

yannsartori avatar Oct 11 '21 21:10 yannsartori

Also in a situation in which you have only removed one item, for example: with a list of {a: [1, 2, 3]} becoming {a: [1, 2]} It is a lot less heavy handed to say {op: remove, path: /a/2} than{op: replace, path: /a, value: [1, 2]}. I do understand that in almost every scenario it is programmatically faster to do a replace, but you are being kind of disingenuous since it's not actually one patch per change, instead you are condensing potentially many changes into 1.

sammaphey avatar Oct 13 '21 21:10 sammaphey

Any updates on this?

yannsartori avatar Dec 02 '21 19:12 yannsartori

It should just be a matter of adding many tests with a and b in diff.json and completing patch with what your implementation comes up with - double check it makes sense and you're good to go.

sonnyp avatar Dec 02 '21 19:12 sonnyp