I have a query like this:
curl -s \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
--data "$(echo $PAYLOAD)" \
https://myapi/client/v4/graphql/ | jq .
... that produces output like this:
{
"data": {
"viewer": {
"accounts": [
{
"magicTransitTunnelTrafficAdaptiveGroups": [
{
"avg": {
"bitRateFiveMinutes": 23360
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "nw-blue"
}
},
{
"avg": {
"bitRateFiveMinutes": 8960
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "mtlab_gcp1"
}
},
{
"avg": {
"bitRateFiveMinutes": 95493
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "Cherry_CBE_1"
}
},
{
"avg": {
"bitRateFiveMinutes": 2968507
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "Cherry_VCB"
}
},
{
"avg": {
"bitRateFiveMinutes": 10880
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "accelia-poc1"
}
},
{
"avg": {
"bitRateFiveMinutes": 21227
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "mtlab_sr_pni"
}
},
{
"avg": {
"bitRateFiveMinutes": 27627
},
"dimensions": {
"datetimeFiveMinutes": "2022-12-30T09:00:00Z",
"tunnelName": "mtlab-tme-gcp1"
}
}
]
}
]
}
},
"errors": null
}
I want to parse all the bitRateFiveMinutes
values, add them up, and stuff them into a variable for evaluation. How do I do this using the jq -r
option? I looked at the examples on https://stedolan.github.io/jq/manual/, but I could not determine what to use. It looks like there is a built-in operator +
that might do the addition for me as well.