You can transform an existing collection by selecting a subset based on filtering criteria, which results in a new collection.

<Collection>.?[<Filter Criteria Expression>] becomes a new collection.

In addition to returning a filtered collection, you can extract the first or last entry in a collection matching the filter criteria.

<Collection>.^[<Filter Criteria Expression>] returns the first element matching the filter criteria.

<Collection>.\$[<Filter Criteria Expression>] returns the last element matching the filter criteria.

Selection Input Output

From an array or collection of numbers, select only the even numbers

{1,2,3,4,5,6,7,8,9,10}.?[#this % 2 == 0]

[2,4,6,8,10]

From an array or collection of numbers, select the first even number

{1,2,3,4,5,6,7,8,9,10}.^[#this % 2 == 0]

2

From an array or collection of numbers, select the last even number

{1,2,3,4,5,6,7,8,9,10}.\$[#this % 2 == 0]

10

For the following input data model, the table following the data model describes possible selections.

{
"user": {
"contacts": [
{
"info": "user01@test.com",
"primary": false,
"type": "email"
},
{
"info": 9876512345,
"primary": true,
"type": "phone"
},
{
"info": 9876511111,
"primary": false,
"type": "phone"
}
]
}
}
Selection Input Output

Select all contact info of type phone

user.contacts.?[type == 'phone']

{
"info": 9876512345,
"primary": true,
"type": "phone"
},
{
"info": 9876511111,
"primary": false,
"type": "phone"
}

Select the first primary contact info

user.contacts.?[primary]

{
"info": 9876512345,
"primary": true,
"type": "phone"
}