【问题标题】:How to split two arrays into object using Dataweave如何使用 Dataweave 将两个数组拆分为对象
【发布时间】:2020-05-23 02:17:18
【问题描述】:

我正在从数据库中获取数据并尝试使用 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】:

您可以即时将 String 更改为 JSON,然后使用它 https://simpleflatservice.com/mule4/ChangeStringToJsonOnTheFly.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
    }
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2021-09-14
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 2015-10-16
    相关资源
    最近更新 更多