使用mule-dataweave进行Json转换
我需要将json(在多次调用后获得,然后将其合并)转换为特定的结构 这是我的输入json负载使用mule-dataweave进行Json转换,json,mule,mule-studio,dataweave,Json,Mule,Mule Studio,Dataweave,我需要将json(在多次调用后获得,然后将其合并)转换为特定的结构 这是我的输入json负载 [{ "shops": [{ "shop": { "code": "AU5", "streetName": "a", "city": "a", "district": "a", "state": "a", "postalCode": "a
[{
"shops": [{
"shop": {
"code": "AU5",
"streetName": "a",
"city": "a",
"district": "a",
"state": "a",
"postalCode": "a",
"country": "a"
}
}, {
"shop": {
"code": "b",
"streetName": "b",
"city": "b",
"district": "b",
"state": "b",
"postalCode": "b",
"country": "b"
}
}]
},
[
[{
"salesOffice": {
"shop": {
"code": "AU5"
},
"office": "MEL",
"branch": "MEL",
"district": "SPR",
"subRegion": "SPR",
"region": "AP"
}
}],
[{
"salesOffice": {
"shop": {
"code": "b"
},
"office": "999",
"branch": "999",
"district": "999",
"subRegion": "999",
"region": "999"
}
}
]
]]
下面是预期的json输出
{
"shops": [
{
"shop": {
"code": "AU5",
"streetName": "a",
"city": "a",
"district": "a",
"state": "a",
"postalCode": "a",
"country": "a",
"salesOffice": {
"office": "MEL",
"branch": "MEL",
"district": "SPR",
"subRegion": "SPR",
"region": "AP"
}
}
},
{
"shop": {
"code": "b",
"streetName": "b",
"city": "b",
"district": "b",
"state": "b",
"postalCode": "b",
"country": "b",
"salesOffice": {
"office": "999",
"branch": "999",
"district": "999",
"subRegion": "999",
"region": "999"
}
}
}
]}
转换时,商店内的“代码”应与salesOffice>>商店内的“代码”匹配
下面是输出负载的Json模式(应根据输出进行验证)
任何解决方案或任何指针都会有很大帮助您可以使用Validate JSON Schema mule组件 您可以使用Validate JSON Schema mule组件 请参阅以下数据:
%dw 1.0
%output application/json
---
{
shops: using (salesOffice = payload[1]..salesOffice)( payload[0].shops map {
shop :
{
code: $.shop.code,
streetName:$.shop.streetName,
city:$.shop.city,
district:$.shop.district,
state:$.shop.state,
postalCode:$.shop.postalCode,
country:$.shop.country,
salesOffice: using (code= $.shop.code) ( salesOffice[?(code == $.shop.code)] map {
office:$.office,
branch:$.branch,
district:$.district,
subRegion:$.subRegion,
region:$.region
})[0]
}
})
}
请参阅以下数据:
%dw 1.0
%output application/json
---
{
shops: using (salesOffice = payload[1]..salesOffice)( payload[0].shops map {
shop :
{
code: $.shop.code,
streetName:$.shop.streetName,
city:$.shop.city,
district:$.shop.district,
state:$.shop.state,
postalCode:$.shop.postalCode,
country:$.shop.country,
salesOffice: using (code= $.shop.code) ( salesOffice[?(code == $.shop.code)] map {
office:$.office,
branch:$.branch,
district:$.district,
subRegion:$.subRegion,
region:$.region
})[0]
}
})
}