开发者

Can we perform multiplication using indexes of the list in jolt?

开发者 https://www.devze.com 2022-12-07 20:08 出处:网络
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].

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

Can we perform multiplication using indexes of the list in jolt?

0

精彩评论

暂无评论...
验证码 换一张
取 消