简体   繁体   English

Mule Dataweave JSON有效内容的空检查和数组空检查

[英]Mule Dataweave null check and array empty check of JSON payloads

Need to check null and empty array in Dataweave using filter or any other logic. 需要使用过滤器或任何其他逻辑检查Dataweave中的空数组和空数组。

First check the parentId is null, we need to skip the particular JSON. 首先检查parentId为null,我们需要跳过特定的JSON。 If parentId is not null need to check the mobileContacts or emailContacts have the array of values. 如果parentId不为null,则需要检查mobileContacts或emailContacts是否具有值数组。 If mobileContacts and emailContacts have empty List we need skip the particular JSON values. 如果mobileContacts和emailContacts的列表为空,则需要跳过特定的JSON值。 If any one have the value we need to process the records. 如果有任何值,我们需要处理记录。

Input 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
    }
  ]
}

Need below Output: 需要以下输出:

{
  "name": "XYZ",
  "age": 23, 
  "results": [
    {
      "parentId": "12345",      
      "notes": "proceed",
      "mobileContacts": [
        {
          "relationId": "12345",
          "callId": "3456213"
        },
        {
          "relationId": null,
          "callId": null
        }
      ],     
      "initial": true
    }
  ]
}

How about this, 这个怎么样,

%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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM