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

Fix for https://github.com/zgrossbart/jdd/issues/3 #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vbro
Copy link

@vbro vbro commented May 1, 2017

Adds an option to ignore the order of elements in arrays by recursively sorting arrays in the JSON object

Adds an option to ignore the order of elements in arrays by recursively sorting arrays in the JSON object
@zgrossbart
Copy link
Owner

Hello Valery,

Thank you very much for your contribution. I've heard a request like this one before, but I've always had one question about it. Arrays in JSON do have a very specific meaning. If you don't want the array order to matter then why not use an object instead of an array?

To put it another way, why would you want an unordered array in JSON?

@vbro
Copy link
Author

vbro commented May 4, 2017

Hi Zack,
Thanks for the response. Yes, JSON arrays are by specification, ordered. However, there are real world scenarios where the order of elements in an array is irrelevant. To use an object to represent an un-ordered list, you may have to store the data as keys and pair them with null / placeholder values. Not an ideal solution either.
This feature is especially useful when debugging, when you may not have control of the data you're dealing with. For me it's more about curiousity; I'm interested in seeing what the data looks like when the arrays are sorted.

@zgrossbart
Copy link
Owner

Hi Valery,

That makes a lot of sense, but I need to think about it a little bit. I've been trying to keep this tool really really simple and explaining something like sorting arrays gets tricky. I'm going to consider this for a little while.

Thanks,
Zack

@vbro
Copy link
Author

vbro commented May 5, 2017

Sounds good. There is always a fine balance between adding new features and keeping a product simple and easy to use. Regardless, you've done a good job on such a great product.

@evenost-helx
Copy link
Contributor

evenost-helx commented May 20, 2017

We could perhaps indicate in the diff output message that the arrays just have a different order but would have been equivalent if they were sorted?

@tw258
Copy link

tw258 commented Dec 28, 2022

Thank you @vbro for your pull request (and of course @zgrossbart for this repo at all). I had the same issue where I wanted to ignore the sorting of the arrays. Your code works just fine for me

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

Successfully merging this pull request may close these issues.

4 participants