JQ examples / cookbook
Last modified: March 23, 2023
group by + count
JQ playground.calls | group_by(.route) | map({key: .[0].route, value: map(.callTimeMs) | length})
group by + add
JQ playground.calls | group_by(.route) | map({key: .[0].route, value: map(.callTimeMs) | add})
helper function
JQ playgrounddef isLocalhost: . == "127.0.0.1";
.hosts[] | {localhost: .host | isLocalhost}
if/else condition
JQ playgrounddef areaFromCountry: if . == "USA" then "North America"
elif . == "Germany" then "Europe"
elif . == "Japan" then "Asia"
else "Unknown"
end;
.countries[] | {area: .name | areaFromCountry}