Contact Us 1-800-596-4880

filterObjectLeafs

filterObjectLeafs(value: Any, criteria: (value: Any, path: Path) -> Boolean): Any

Applies a filtering expression to leaf or Path values of keys in an object.

The leaf values in the object must be SimpleType or Null values. See Core Types for descriptions of the types.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

value

An input value of Any type.

criteria

Boolean expression to apply to SimpleType or Null leaf values of all objects in the input value. If the result is true, the object retains the leaf value and its key. If not, the function removes the leaf value and key from the output.

Example

This example shows how filterObjectLeafs behaves with different inputs.

Source

%dw 2.0
import * from dw::util::Tree
var myArray = [{name @(mail: "me@me.com", test:123 ): "", id:"test"},
               {name: "Me", id:null}]
output application/json
---
{
 a: {
     name: "Mariano",
     lastName: null,
     age: 123,
     friends: myArray
    }  filterObjectLeafs ((value, path) ->
         !(value is Null or value is String)),
 b: { c : null, d : "hello" } filterObjectLeafs ((value, path) ->
         (value is Null and isObjectType(path)))
}

Output

{
  "a": {
    "age": 123,
    "friends": [
      {

      },
      {

      }
    ]
  },
  "b": {
    "c": null
  }
}