Using jq, I extracted a json array from a data source that looks something like this:
[
{
"rank": 69,
"name": "Luigi"
},
{
"rank": 420,
"name": "Peach"
},
{
"rank": 666,
"name": "Toad"
},
{
"rank": 42,
"name": "Mario"
}
]
Is there an elegant way of extracting the highest value of a field in the array within a shell script? In this example, I'm trying to get "666". I could write a dedicated program to do this easily, but I'd prefer to stay in a single shell script, unless it's too ugly to do that. I'm in the context of an Ubuntu Docker container and can install additional packages if needed.
grep -Eo '[[:digit:]]+' file.json | sort -n | tail -n1