Skip to content

How to sort/reorder by the value of a map, not the key #2089

Closed Answered by ccoVeille
ccoVeille asked this question in Q&A

You must be logged in to vote

Found it after reading the documentation again, and playing with map to array conversion

yq '.swap |= ((to_entries | sort_by(.value | downcase)) | from_entries) '

to_entries/from_entries =>https://mikefarah.gitbook.io/yq/operators/entries#from_entries-map
sort_by => https://mikefarah.gitbook.io/yq/operators/sort-keys
downcase => https://mikefarah.gitbook.io/yq/operators/string-operators

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by ccoVeille
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant