Finding the five biggest of something in an API response is a two step filter in jq: sort, then slice.
jq -c 'sort_by(-.mem) | .[:2] | map(.name)' containers.json
# ["db","web"]
jq -r 'sort_by(.updated) | reverse | .[:5][] | .name' repos.json
sort_by(.mem) sorts the array from small to large on that field. For biggest first I’d either negate a number, like -.mem, or add reverse afterwards, which also works for strings and dates. Then .[:5] slices off the first five, the same slice syntax Python uses. Adding [] after the slice unpacks the result so each item goes on its own line.
You can sort on several fields at once with sort_by(.state, .name): first on state, and on name when states are equal.
The trap is missing values. Records without the field get null, and in jq null sorts before everything else. With reverse those end up last, which is fine, but with -.mem jq throws an error because you can’t negate null. If some records lack the field, give it a default first: sort_by(-(.mem // 0)). Also, ISO dates sort fine as strings, but dates like 30-11-2026 don’t.
Further reading: jq manual: sort, sort_by, jq manual: slices