Sorting and Counting
The next problem I have is that I want to summarize some this JSON data. Each issue returned by GitHub has a collection of labels:
If I want those labels in alphabetical order I can use the built in sort function. It works like this:
This is similar to how I would sort an array in JavaScript:
const l = ["3", "2", "1"];
l.sort();Other built-ins that mirror JavaScript functionality are available, like length, reverse, and tostring and they can all be used in a similar way:
If I can combine these built-ins with the selectors I’ve built up so far, I’ll have solved my label sorting problem. So I’ll show that next.
What I Learned: Array-Index:
jq has many built-in functions. There are probably too many to remember but the built-ins tend to mirror JavaScript functions, so give those a try before heading to the jq manual, and you might get lucky.