Can we perform multiplication using indexes of the list in jolt?
I'm tryi开发者_StackOverflow社区ng to perform the multiplication of two different lists.
Is this possible to perform the multiplication corresponding indexes of the lists like list1[i] * list2[i].
Input JSON
{
"salesTaxAmount": [
5.2,
5.2,
5.2
],
"quantity": [
1,
2,
1
],
"unitAmount": [
20,
20,
20
]
}
Expected output
{
"totalAmount":[20,40,20]
}
Here I want the totalAmount
like quantity * unitAmount
.
Could someone help me, please.
Thanks!
There's no function such like multiply or product to be used within a modify spec but can be simulated by using divide
function after reforming individual objects by a shift transformation such as
[
{
"operation": "shift",
"spec": {
"q*|u*": {
"*": "&.&1"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"prd_quantity": "=divide(1,@(1,quantity))",
"Amt_": "=divide(@(1,unitAmount),@(1,prd_quantity))",
"Amt": "=toInteger(@(1,Amt_))"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"Amt": "totalAmount[]"
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
精彩评论