%dw 2.0
import * from dw::util::Tree
var myObject = {
user: [{
name: "mariano",
lastName: "achaval",
friends: [
{
name: "julian"
},
{
name: "tom"
}
]
},
{
name: "leandro",
lastName: "shokida",
friends: [
{
name: "peter"
},
{
name: "robert"
}
]
}
]
}
output application/json
---
{
mariano : myObject nodeExists ((value, path) -> path[-1].selector == "name" and value == "mariano"),
julian : myObject nodeExists ((value, path) -> path[-1].selector == "name" and value == "julian"),
tom : myObject nodeExists ($$[-1].selector == "name" and $ == "tom"),
leandro : myObject nodeExists ($$[-1].selector == "name" and $ == "leandro"),
peter : myObject nodeExists ($$[-1].selector == "name" and $ == "peter"),
wrongField: myObject nodeExists ($$[-1].selector == "wrongField"),
teo: myObject nodeExists ($$[-1].selector == "name" and $ == "teo")
}
nodeExists
nodeExists(value: Any, callback: (value: Any, path: Path) -> Boolean): Boolean
Returns true
if any node in a given tree validates against
the specified criteria.
Introduced in DataWeave version 2.2.2.
Parameters
Name | Description |
---|---|
|
The value to search. |
|
The criteria to apply to the input |
Example
This example checks for each user by name and last name. Notice
that you can also reference a value
with $
and the path
with $$
.