---
title: Collection operations
description: You can use PingOne Expression Language collection operations to transform existing collections.
component: pingone
page_id: pingone:pingone_expression_language:p1_expressionlang_collection_operations
canonical_url: https://docs.pingidentity.com/pingone/pingone_expression_language/p1_expressionlang_collection_operations.html
revdate: April 25, 2025
page_aliases: ["p1_expressionlang_collection_selection.adoc", "p1_expressionlang_collection_projection.adoc"]
section_ids:
  p1-exp-lang-collect-select: Collection selection
  p1-exp-lang-collect-project: Collection projection
---

# 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 | `{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.

```json
{
    "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']` | ```json
{
  "info": 9876512345,
  "primary": true,
  "type": "phone"
},
{
  "info": 9876511111,
  "primary": false,
  "type": "phone"
}
``` |
| Select the first primary contact info   | `user.contacts.?[primary]`         | ```json
{
  "info": 9876512345,
  "primary": true,
  "type": "phone"
}
```                                                                  |

## 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:

```json
{
    "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                       | `user.contacts.![type]`                                | `["email", "phone", "phone"]`      |
| Extract all primary info attributes                             | `user.contacts.?[primary].![info]`                     | `[9876512345]`                     |
| Extract the primary info attribute as a different object format | `user.contacts.?[primary].![{'primaryContact': info}]` | `[{"primaryContact": 9876512345}]` |
