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
}]
}
2
Answers
Is there also a solution if the value to multiply itself is in an array? In this example multiply lvalue from outer location array with value from inner cities value.
Given JSON:
Expected Value in one JSON:
You need to ‘save’ the
.value
in a variable before looping over the locations to update them using|=
:JqPlay Demo