PingOne

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.

{
    "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"
}

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

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}]