使用 Mule 3 进行嵌套数组数据转换
Nested array data transformation with Mule 3
我正在尝试在 Mule 3 (DataWeave 1.0) 中转换数据,但没有得到想要的结果。
这是输入负载:
[
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "8db55441-6255-4d24-8d39-658536985214",
"number": "0w-30",
"Desc": "maintain"
}
],
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "11111111-6666-2222-3g3g-854712547412",
"number": "5w-40",
"Desc": "on prod"
}
],
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "1ab32c5b-ffs3-3243-74fv-3376218042bb",
"number": "5w-30",
"Desc": "on test"
}
]
]
我的愿望输出需要像下面这样
{
"@odata.context": "https://scrum-caller.com/repo/v1/inside#Changes",
"value": [
{
"id": "8db55441-6255-4d24-8d39-658536985214",
"number": "0w-30",
"Desc": "maintain"
},
{
"id": "11111111-6666-2222-3g3g-854712547412",
"number": "5w-40",
"Desc": "on prod"
},
{
"id": "1ab32c5b-ffs3-3243-74fv-3376218042bb",
"number": "5w-30",
"Desc": "on test"
}
]
}
感谢大家的帮助。
假设所有的url都是相同的,因为问题没有提供细节只是一个例子,我只是把第一个元素作为“@odata.context”的输入值,这个值只是过滤掉 non-array 元素并使用 reduce 运算符获取其他元素的单个数组。
%dw 1.0
%output application/json
---
{
"@odata.context" : payload[0],
value : payload filter ($ is :array) reduce ($ ++ $$)
}
我正在尝试在 Mule 3 (DataWeave 1.0) 中转换数据,但没有得到想要的结果。
这是输入负载:
[
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "8db55441-6255-4d24-8d39-658536985214",
"number": "0w-30",
"Desc": "maintain"
}
],
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "11111111-6666-2222-3g3g-854712547412",
"number": "5w-40",
"Desc": "on prod"
}
],
"https://scrum-caller.com/repo/v1/inside#Changes",
[
{
"id": "1ab32c5b-ffs3-3243-74fv-3376218042bb",
"number": "5w-30",
"Desc": "on test"
}
]
]
我的愿望输出需要像下面这样
{
"@odata.context": "https://scrum-caller.com/repo/v1/inside#Changes",
"value": [
{
"id": "8db55441-6255-4d24-8d39-658536985214",
"number": "0w-30",
"Desc": "maintain"
},
{
"id": "11111111-6666-2222-3g3g-854712547412",
"number": "5w-40",
"Desc": "on prod"
},
{
"id": "1ab32c5b-ffs3-3243-74fv-3376218042bb",
"number": "5w-30",
"Desc": "on test"
}
]
}
感谢大家的帮助。
假设所有的url都是相同的,因为问题没有提供细节只是一个例子,我只是把第一个元素作为“@odata.context”的输入值,这个值只是过滤掉 non-array 元素并使用 reduce 运算符获取其他元素的单个数组。
%dw 1.0
%output application/json
---
{
"@odata.context" : payload[0],
value : payload filter ($ is :array) reduce ($ ++ $$)
}