An API returns a JSON array like this:
[
{
"name": "Rangsdorf, Bahnhof",
"lat": 52.294125,
"lon": 13.431112
},
{
"name": "Leipzig, Hauptbahnhof",
"lat": 51.344817,
"lon": 12.381321
},
{
"name": "Senftenberg, Bahnhof",
"lat": 51.52679,
"lon": 14.003977
},
[...]
]
I'd like to retrieve that (or one) dict out of the array with the most northern position (i. e. where lat
has a maximum) using jq
. In the example, I'd expect either
{
"name": "Rangsdorf, Bahnhof"
}
or, even better
{
"name": "Rangsdorf, Bahnhof",
"lat": 52.294125,
"lon": 13.431112
}
as a result using jq
.
<file.json jq 'max_by(.lat)'
, or also an easy and invariant solution withjtc
:<file.json jtc -w'[lat]:<>G[-1]'