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

Allow sorting of arrays #28

Open
EliteMasterEric opened this issue Feb 18, 2021 · 2 comments
Open

Allow sorting of arrays #28

EliteMasterEric opened this issue Feb 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@EliteMasterEric
Copy link
Contributor

EliteMasterEric commented Feb 18, 2021

This would be disabled by default obviously, since in many circumstances it would cause breaking changes.

By default, JavaScript calling Array.sort() on an array has odd behavior. Notably, objects will not have fully defined behavior and numbers will be sorted as strings (!!!).

Thus, my suggestion is that this functionality be added as part of #27, which will allow users to specify the sorting algorithm used for arrays, separately from object keys. If no sorting algorithm is specified for arrays, it can be assumed that the user does not want JavaScript's default confusing sorting behavior, and sorting of arrays will be disabled.

@Gudahtt Gudahtt added the enhancement New feature or request label Feb 22, 2021
@Gudahtt
Copy link
Owner

Gudahtt commented Feb 22, 2021

Hah, I was guessing that someone would ask for this! This would be a good feature, as long as it was opt-in, as you suggested.

@EliteMasterEric
Copy link
Contributor Author

It would absolutely have to be opt-in, because for many cases (but not all, hence the reason for this issue) the order of the elements in a JSON array is significant. Having it as an option would be convenient, though.

One issue is that in some cases you do not know which array you are sorting. With #27 providing a JavaScript function, the user could check for the type of the items being sorted before sorting. Alternatively, we could provide a third function parameter which provides the path of the variable being sorted.

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

No branches or pull requests

2 participants