gpt4 book ai didi

mule - 在 Mulesoft Dataweave 2.0 中展开数组

转载 作者:行者123 更新时间:2023-12-04 09:44:16 35 4
gpt4 key购买 nike

我有一个扁平的客户数组,但找不到合适的方法(方式)来展开它,以便每个客户和他的年龄都嵌套。

输入

{
"1st Customer": "2216",
"Age": "90",
"2nd Customer": "2231",
"Age": "90",
"3rd Customer": "2249",
"Age": "120",
"4th Customer": "2302",
"Age": "150",
"5th Customer": "",
"Age": ""
}

输出
{
"customers": [
{
"CustomerSeq": "1",
"CustomerID": "2216",
"Age": 90,
},
{
"CustomerSeq": "2",
"CustomerID": "2231",
"Age": 90,
},
{
"CustomerSeq": "3",
"CustomerID": "2249",
"Age": 120,
},
{
"CustomerSeq": "5",
"CustomerID": "2302",
"Age": 150,
}
]
}

最佳答案

非常感谢,亚历克斯
除法正是我要找的

解决方案[包括去除空值]:

%dw 2.0
output application/json

import * from dw::core::Objects
---
customers:
((payload filterObject ((value, key, index) -> value != "")) divideBy 2) map (
(pCustomer, indexOfpCustomer) -> {
CustomerSeq:indexOfpCustomer+1,
CustomerID: pCustomer[0],
Age: pCustomer[1]
})

关于mule - 在 Mulesoft Dataweave 2.0 中展开数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62193178/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com