json - 如何使用 Dataweave 将两个数组拆分为对象
问题描述
我正在从数据库中获取数据并尝试使用 dataweave 进行分配。但是,我查看是否为查询获取多个值,然后它将列的所有值组合到单个数组中。
目前使用我的数据编织逻辑它返回我这个输出
电流输出:
"orders": [
{
"orderID": "[10355, 10383, 10453]",
"employeeID": "[6, 8, 1]"
}
]
预期输出:
"orders": [
{
"orderID": "103553",
"employeeID": "6"
},
{
"orderID": "10383",
"employeeID": "8"
},
{
"orderID": "10453",
"employeeID": "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
}
]
}
推荐阅读
- sql - 每天查找上周订购的客户?
- reactjs - 如何将 Facebook 聊天信使添加到 Next.js?
- javascript - Redmine Plugins - Redmin Checklist 错误,.checklist() 不是函数
- html - 在正文和块后的空间中滚动
- php - FPDF - 一些特殊字符不起作用
- fasttext - fastText 可以使用比 RAM 更大的语料库进行训练吗?
- tensorflow - Opencv 和 tensorflow 的 pbtxt 文件
- android-studio - Android Studio 4.1 和 4.2.2 中缺少 Java 库选项
- performance - GPU RTX 2080 Ti tensorflow 运行速度比 CPU tensorflow 慢?
- c# - 将多种方法浓缩为一种