Mule 使用Dataweave拆分表列中的连接值
我的Salesforce表中有如下示例数据:Mule 使用Dataweave拆分表列中的连接值,mule,mule-component,anypoint-studio,dataweave,mulesoft,Mule,Mule Component,Anypoint Studio,Dataweave,Mulesoft,我的Salesforce表中有如下示例数据: [ {"Id": "634594cc","Name": "Alpha","List": "AB01"}, {"Id": "634594cc","Name": "Alpha","List": "AB02"}, {"Id": "634594cc","Name": "Alpha","List": "AB03"}, {"Id": "5d839e9c","Name": "Bravo","List": "CD01"
[
{"Id": "634594cc","Name": "Alpha","List": "AB01"},
{"Id": "634594cc","Name": "Alpha","List": "AB02"},
{"Id": "634594cc","Name": "Alpha","List": "AB03"},
{"Id": "5d839e9c","Name": "Bravo","List": "CD01"},
{"Id": "5d839e9c","Name": "Bravo","List": "CD02"},
{"Id": "3a5f34d3","Name": "Charlie","List": null}
]
我在Mule 3.9上运行dataweave 1.0。
我需要使用dataweave读取上述数据(来自Salesforce表),并将其转换为JSON,如下所示:
[
{"Id": "634594cc","Name": "Alpha","List": "AB01"},
{"Id": "634594cc","Name": "Alpha","List": "AB02"},
{"Id": "634594cc","Name": "Alpha","List": "AB03"},
{"Id": "5d839e9c","Name": "Bravo","List": "CD01"},
{"Id": "5d839e9c","Name": "Bravo","List": "CD02"},
{"Id": "3a5f34d3","Name": "Charlie","List": null}
]
正如您在上面看到的,“List”列是我需要在最终JSON中拆分为单独数组的内容。它的数据开头、中间和结尾都带有分号
提前感谢您的帮助。我冒昧地创建了两个基于SS的示例数据(顺便说一句,最好不要使用SS):) 试试这个:
%dw 1.0
%output application/dw
%var data = [
{
id: "ABC123",
name: "A",
list: ";AB1;AB2;AB3;"
},
{
id: "ZXY321",
name: "B",
list: null
}
]
---
data reduce (e,result=[]) -> (
result ++ using (
list = e.list default "" splitBy /;/ filter ($ != ""),
sharedFields = {
Id: e.id,
Name: e.name
}
) (
using (
flist = list when ((sizeOf list) > 0) otherwise [null]
) (
flist map {
(sharedFields),
List: $
}
)
)
)
我根据SS(顺便说一句,最好不要使用SS)创建了两个示例数据 试试这个:
%dw 1.0
%output application/dw
%var data = [
{
id: "ABC123",
name: "A",
list: ";AB1;AB2;AB3;"
},
{
id: "ZXY321",
name: "B",
list: null
}
]
---
data reduce (e,result=[]) -> (
result ++ using (
list = e.list default "" splitBy /;/ filter ($ != ""),
sharedFields = {
Id: e.id,
Name: e.name
}
) (
using (
flist = list when ((sizeOf list) > 0) otherwise [null]
) (
flist map {
(sharedFields),
List: $
}
)
)
)
非常感谢您的回复。让我用我的数据试试这个:-)非常感谢你的回复。让我用我的数据试试这个:-)