如何使用Dataweave将两个数组拆分为一个对象?

问题描述 投票:0回答:1

我正在从数据库中获取数据,并尝试使用dataweave进行赋值。但是,我看到如果一个查询有多个值,那么它就会把所有列的值合并成一个数组。

目前,我的dataweave逻辑是返回我的这个输出

当前输出。

"orders": [
        {
          "orderID": "[10355, 10383, 10453]",
          "employeeID": "[6, 8, 1]"
        }
      ]

预期产出:

"orders": [
            {
              "orderID": "103553",
              "employeeID": "6"
            },
            {
              "orderID": "10383",
              "employeeID": "8"
            },
            {
              "orderID": "10453",
              "employeeID": "1"
            }
          ]

先谢谢你

json mule dataweave
1个回答
1
投票

你可以在飞行中把String改为JSON,然后使用它。https:/simpleflatservice.commule4ChangeStringToJsonOnTheFly.html。

%dw 2.0
var x={"orders": [
        {
          "orderID": "[10355, 10383, 10453]",
          "employeeID": "[6, 8, 1]"
        }
      ]    
}
output application/json
---
{
    orders: read(x.orders[0].orderID,'application/json') map (item,index) ->
    {
        orderID:item, 
        "employeeID": read(x.orders[0].employeeID,'application/json')[index]
    }
}

产出

{
  "orders": [
    {
      "orderID": 10355,
      "employeeID": 6
    },
    {
      "orderID": 10383,
      "employeeID": 8
    },
    {
      "orderID": 10453,
      "employeeID": 1
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.