【问题标题】:Mule Dataweave null check and array empty check of JSON payloadsJSON有效负载的Mule Dataweave空检查和数组空检查
【发布时间】:2018-02-24 06:20:13
【问题描述】:

需要使用过滤器或任何其他逻辑检查 Dataweave 中的 null 和空数组。

首先检查 parentId 是否为空,我们需要跳过特定的 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
    }
  ]
}

【问题讨论】:

标签: arrays json mule dataweave


【解决方案1】:

这个怎么样,

%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))
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    相关资源
    最近更新 更多