Created
July 12, 2017 20:40
-
-
Save sloanlance/ae54cf055e3d7713a9b76c1abe2d8292 to your computer and use it in GitHub Desktop.
jq: Functions to sort the *properties* of an object by key or value. I believe these are largely part of the recent versions of jq, but I think they're interesting. From the poorly-named repo https://github.com/joelpurra/jq-object-sorting (which sorts properties, not objects).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def byKeyAsc: | |
to_entries | |
| sort_by(.key) | |
| from_entries; | |
def byKeyDesc: | |
to_entries | |
| sort_by(.key) | |
| reverse | |
| from_entries; | |
def byValueAsc: | |
to_entries | |
| sort_by(.value) | |
| from_entries; | |
def byValueDesc: | |
to_entries | |
| sort_by(.value) | |
| reverse | |
| from_entries; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment