[英]Mule Dataweave null check and array empty check of JSON payloads
需要使用过滤器或任何其他逻辑检查Dataweave中的空数组和空数组。
首先检查parentId为null,我们需要跳过特定的JSON。 如果parentId不为null,则需要检查mobileContacts或emailContacts是否具有值数组。 如果mobileContacts和emailContacts的列表为空,则需要跳过特定的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
}
]
}
这个怎么样,
%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))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.