---
schema_version: "1"
id: 63e2d14261516ff345220764c1b485ed9f4819d849339bb2694bc1976d289bab
title: filterTree
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-tree-functions-filtertree.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-tree-functions-filtertree
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 97f23899200f0ca000490e931ed124b4a6621d24230f3c223579f32197eae146
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# filterTree

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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

Filters the value or path of nodes in an input based on a specified `criteria`.

The function iterates through the nodes in the input. The `criteria` can apply to the value or path
in the input. If the `criteria` evaluates to `true`, the node remains in the output. If `false`, the
function filters out the node.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>value</code></p></td><td><p>The value to filter.</p></td></tr><tr><td><p><code>criteria</code></p></td><td><p>The expression that determines whether to filter the node.</p></td></tr></tbody></table>

### Example

This example shows how `filterTree` behaves with different inputs. The output is `application/dw`
for demonstration purposes.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Tree
output application/dw
---
{
    a: {
          name : "",
          lastName @(foo: ""): "Achaval",
          friends @(id: 123): [{id: "", test: true}, {age: 123}, ""]
        } filterTree ((value, path) ->
            value match  {
                            case s is String -> !isEmpty(s)
                            else -> true
                          }
    ),
    b: null filterTree ((value, path) -> value is String),
    c: [
            {name: "Mariano", friends: []},
            {test: [1,2,3]},
            {dw: ""}
        ] filterTree ((value, path) ->
            value match  {
                            case a is Array ->  !isEmpty(a as Array)
                            else -> true
                        })
}
```

#### Output

```DataWeave
{
  a: {
    lastName: "Achaval",
    friends @(id: 123): [
      {
        test: true
      },
      {
        age: 123
      }
    ]
  },
  b: null,
  c: [
    {
      name: "Mariano"
    },
    {
      test: [
        1,
        2,
        3
      ]
    },
    {
      dw: ""
    }
  ]
}
```
