我一直在努力想出一种用jq
对任意嵌套字段求和的方法。两次调用之间“存储桶”的级别有所不同(汇总字段的不同级别)。那么,如何对以下代码段中的所有avg_amount
字段求和(理想情况下不对每个.buckets.[]
进行硬编码)?
[
{
"buckets":[
{
"buckets":[
{
"buckets":[
{
"avg_amount":25,
}
],
"destination":"Apple"
},
{
"buckets":[
{
"avg_amount":74,
}
],
"destination":"Google"
}
],
"vendor_name":"Vendor Bee"
},
{
"buckets":[
{
"buckets":[
{
"avg_amount":1000,
}
],
"destination":""
}
],
"vendor_name":""
}
],
"company_id":1
}
]
谢谢!