Cheatsheet Pages / jq Cheatsheet
How to find the top or bottom object by a field with jq — max_by and min_by
Who scored highest? Who is youngest? You want the whole winning object, not just the value.
Every filter was executed against the cheatsheet's sample config.json with jq 1.7 before publishing; the sample file sits at the bottom of the cheatsheet so you can reproduce every output.
jq '.users | max_by(.score) | {name, score}' config.json
# output: { "name": "ana", "score": 92 }
jq '.users | min_by(.age) | {name, age}' config.json
# output: { "name": "bruno", "age": 17 }
