需要使用过滤器或任何其他逻辑检查Dataweave中的null和空数组。
首先检查parentId是否为null,我们需要跳过特定的JSON。如果parentId不为null,则需要检查mobileContacts或emailContacts 拥有值数组。如果mobileContacts和emailContacts有空List,我们需要跳过特定的JSON值。如果任何人拥有我们处理记录所需的价值。
输入JSON:
{
"name": "XYZ",
"age": 23,
"results": [
{
"parentId": "12345",
"notes": "proceed",
"mobileContacts": [
{
"relationId": "12345",
"callId": "3456213"
},
{
"relationId": "12345",
"callId": "12345"
}
],
"emailContacts": [ ],
"initial": true
},
{
"parentId": "435638",
"notes": "proceed",
"mobileContacts": [ ],
"emailContacts": [ ],
"initial": true
},
{
"parentId": null,
"notes": "proceed",
"mobileContacts": [
{
"relationId": "12345",
"callId": "3456213"
},
{
"relationId": "12345",
"callId": "12345"
}
],
"emailContacts": [ ],
"initial": true
}
]
}
需要以下输出:
{
"name": "XYZ",
"age": 23,
"results": [
{
"parentId": "12345",
"notes": "proceed",
"mobileContacts": [
{
"relationId": "12345",
"callId": "3456213"
},
{
"relationId": null,
"callId": null
}
],
"initial": true
}
]
}
答案 0 :(得分:0)
这个怎么样,
%dw 1.0
%output application/json
---
{
name: payload.name,
age: payload.age,
results: payload.results filter ($.parentId != null and ((sizeOf $.mobileContacts) > 0 or (sizeOf $.emailContacts) > 0))
}