Not sure if it is possible. I want multiply the "value" field with the "lvalue" field an put the result in a new field "calc" in the corresponding array entry.
Given JSON:
{
"value": 5,
"location": [{
"city": "San Fracisco",
"lvalue": 10
},
{
"city": "Los Angeles",
"lvalue": 20
}]
}
Expected Value in one JSON:
{
"value": 5,
"location": [{
"city": "San Fracisco",
"lvalue": 10,
"calc": 50
},
{
"city": "Los Angeles",
"lvalue": 20,
"calc": 100
}]
}
>Solution :
You need to ‘save’ the .value in a variable before looping over the locations to update them using |=:
.value as $val | .location[] |= (.calc = $val * .lvalue)