-
Notifications
You must be signed in to change notification settings - Fork 60
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
Implement --sort-keys
#149
Comments
I understand the usefulness of sorting keys, but this functionality could be equally well implemented as a filter. What do you think about including the following definition in jaq? def sort_keys: walk(if isobject then to_entries | sort_by(.key) | from_entries end); That would allow you to replace |
I just realised that def sort_keys: walk(if isobject then to_entries | from_entries end); We can make that more performant by unfolding def sort_keys: walk(if isobject then [keys[] as $k | { ($k): .[$k] }] | add + {} end) Unfolding def sort_keys: walk(if isobject then reduce (keys[] as $k | { ($k): .[$k] }) as $o ({}; . + $o) end); And that's probably how fast it gets when doing it by definition. Testing:
|
@01mf02 Implementing it as a filter instead of a commandline option would be fine for me, thanks! As far as I know, jq only supports the
Is this on purpose? I ask because jq explicitly does not sort the keys since commit jqlang/jq@4a57b84. |
@01mf02 wrote:
If so, that is (or should be considered) a bug. |
No, that was not on purpose. 484dd27 should now correct this. Thanks for spotting this! @pkoppstein, what would you think about including the proposed |
@01mf02 asked:
My only strong preference regarding these matters is that jaq's It may, however, be of interest to know that some of the jq maintainers have a strong distaste for command-line options and seem only to retain -S mainly for the sake of backwards compatibility. In this particular case, Another consideration is that if jaq defines sort_keys before jq, then that will introduce a discrepancy and hence add confusion and noise. |
That is understandable.
I do not understand why you classify this as "unnecessary bloat". Many filters in
That is correct. I would like to avoid such discrepancy. That's why I opened an issue in the jq repository in order to see whether we can proceed in a synchronised way. |
Sorting the keys is quite useful, e.g. when comparing two json files.
The text was updated successfully, but these errors were encountered: