Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array detectMove #14

Open
akrobet opened this issue Mar 28, 2017 · 9 comments
Open

Array detectMove #14

akrobet opened this issue Mar 28, 2017 · 9 comments

Comments

@akrobet
Copy link

akrobet commented Mar 28, 2017

Hi,
Any chance you could add a detectMove parameter for array comparison, so reordered arrays with matching elements are not detected as a difference?
i.e. these two objects would match?

{'name':'John Doe','positions':[ 1, 2, 3 ] }
{'name':'John Doe','positions':[ 1, 3, 2 ] }

@arbitertl
Copy link
Contributor

I might be wrong, but this is not the purpose of that library.

Though you can easily achieve that by first bringing JSON to some canonical form (e.g. sort all arrays in your case).

@wbish
Copy link
Owner

wbish commented Apr 12, 2017

@arbitertl I think it makes sense to add this. jsondiffpatch.net is just a port of benjamine/jsondiffpatch after all and that library does support this feature. If any of you guys want to write the code, feel free, if not I'll eventually get around to it when I have more free time.

@majdisorder
Copy link

majdisorder commented Jun 2, 2018

I'd be happy to have a go at this.

Did you have any specific approach in mind, or shall I just forge ahead?

@wbish
Copy link
Owner

wbish commented Jun 2, 2018

Hey @dimi3tron, thanks for volunteering! I don't have specific requirements, but as a guiding principle, I would really love it if you could implement in a way that mimics the default behavior of the original library. Thanks!

@majdisorder
Copy link

Okay. I'm going by https://github.com/benjamine/jsondiffpatch/blob/master/docs/arrays.md. It pretty much describes what I had in mind anyway.

@majdisorder
Copy link

majdisorder commented Jun 4, 2018

I implemented the basic detectmove algorithm. I works fine for arrays of primitive types and strings.
I haven't gotten around to implementing objecthash, so arrays of objects are still returned as arrays of diffed objects.

I'd have to look at the original code, but I suspect some refactoring will need to be done to get this in place.
Should we go by the same definition of objecthash as the orginal project? It shouldn't be too hard to elaborate and use some .net features to get a better hash.

How do I go about committing my changes?

@butlerpeter
Copy link

@dimi3tron Do you have your changes available in a repository somewhere?

This library looks to be ideal for a project I'm working on but I really need the array move detection.

@sebasijan
Copy link

Is there any update on this?

We need to ignore order when diffing arrays, but don't want to sort each array first

@dantedallag
Copy link

@wbish I am looking to implement this. Has there been any update (I understand it's been a long time) or progress I should be aware of?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants