Open vbro opened 7 years ago
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?
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.
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
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.
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?
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
Adds an option to ignore the order of elements in arrays by recursively sorting arrays in the JSON object