Collection operations
You can use collection operations to transform existing collections.
Collection selection
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 |
|
|
From an array or collection of numbers, select the first even number |
|
|
From an array or collection of numbers, select the last even number |
|
|
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 |
|
|
Select the first primary contact info |
|
|
Collection projection
You can transform an existing collection by applying transformations on the input collection’s data or by selecting specific data, which results in a new collection containing entirely different data sets.
<Collection>.![<Projection Expression>]
becomes a new collection.
For the following input data model, the table following the data model describes possible projections:
{
"user": {
"contacts": [
{
"info": "user01@test.com",
"primary": false,
"type": "email"
},
{
"info": 9876512345,
"primary": true,
"type": "phone"
},
{
"info": 9876511111,
"primary": false,
"type": "phone"
}
]
}
}
Projection | Input | Output |
---|---|---|
Transform to a list of contact types only |
|
|
Extract all primary info attributes |
|
|
Extract the primary info attribute as a different object format |
|
|