See the supported connectors for Application Integration.

FILTER function

FILTER function

Function Name Description Usage Input parameter Return value
FILTER Filters the array elements that satisfy a given filter condition.

Note that a filter condition must evaluate to TRUE or FALSE.

A filter condition includes one or more transformation functions applied on the current array iteration element.

FILTER(~objn -> Variable or Value)

Where ~objn indicates the current array element for which you want to apply the transformation functions. By default, the value for n starts from 1.

For JSON arrays with schema, you can use a dot (.) notation following the current array element to directly access the nested property of the that array element. For example, ~objn.PROPERTY.

A filter condition that evaluates to TRUE or FALSE. An array of elements that match the filter condition.

Supported data type

The FILTER function supports the following data types:

  • Boolean array
  • Double array
  • Integer array
  • JSON
  • String array

Example 1: Filter a string array.

Sample data: $var1$ = { "sara@example.com", "bola@example.com", "222larabrown@gmail.com", "dana@examplepetstore.com", "cloudysanfrancisco@gmail.com"}

Usage: $var1$.FILTER(~obj1-> ~obj1.CONTAINS("@gmail.com"))

Filter the string elements which contain @gmail.com in var1.

Output: {"222larabrown@gmail.com","cloudysanfrancisco@gmail.com"}

Example 2: Filter a JSON array.

Sample data:

  $var1$ = {
  "citynames": [
    {
      "city": "Abbeville",
      "state": "Louisiana"
    },
    {
      "city": "Aberdeen",
      "state": "Maryland"
    },
    {
      "city": "Benicia",
      "state": "California"
    },
    {
      "city": "Chehalis",
      "state": "Washington"
    },
    {
      "city": "Aberdeen",
      "state": "Washington"
    },
    {
      "city": "Aberdeen",
      "state": "Mississippi"
    },
    {
      "city": "Cheektowaga",
      "state": "New York"
    }
  ]
}

Usage:

var1.citynames
.FILTER(~obj1-> 
    ~obj1
    .GET_PROPERTY("city")
    .EQUALS("Aberdeen")
)

Filter the elements which have the city as Aberdeen in var1.

Output:

  [{
    "city": "Aberdeen",
    "state": "Maryland"
  },
  {
    "city": "Aberdeen",
    "state": "Washington"
  },
  {
    "city": "Aberdeen",
    "state": "Mississippi"
  }]

Example 3: Filter a nested JSON array.

Sample data:

  $var1$ =
{
  "products": [
    {
      "PA": "Integrations",
      "users": [
        {
          "name": "Ariel",
          "role": [
            "editor",
            "approver"
          ]
        },
        {
          "name": "Dana",
          "role": [
            "admin",
            "deployer"
          ]
        },
        {
          "name": "Lee",
          "role": [
            "viewer"
          ]
        }
      ]
    },
    {
      "PA": "Apigee",
      "users": [
        {
          "name": "Mahan",
          "role": [
            "editor",
            "admin",
            "deployer"
          ]
        },
        {
          "name": "Quinn",
          "role": [
            "invoker"
          ]
        }
      ]
    },
    {
      "PA": "Connectors",
      "users": [
        {
          "name": "Kiran",
          "role": [
            "invoker",
            "admin",
            "deployer"
          ]
        },
        {
          "name": "Sasha",
          "role": [
            "admin"
          ]
        }
      ]
    }
  ]
}

Usage:

    var1.products
    .FOR_EACH(~obj1 ->
      ~obj1
    .SET_PROPERTY(
        ~obj1
      .GET_PROPERTY("users")
      .FILTER(~obj2 ->
        ~obj2
        .GET_PROPERTY("role")
        .TO_STRING()
        .CONTAINS("admin")
      )
       ,  
    "users"
    )
  )      

Filter the elements which contain admin in users of var1.

Output:

    [{
      "PA": "Integrations",
      "users": [{
        "name": "Dana",
        "role": ["admin", "deployer"]
      }]
    }, {
      "PA": "Apigee",
      "users": [{
        "name": "Mahan",
        "role": ["editor", "admin", "deployer"]
      }]
    }, {
      "PA": "Connectors",
      "users": [{
        "name": "Kiran",
        "role": ["invoker", "admin", "deployer"]
      }, {
        "name": "Sasha",
        "role": ["admin"]
      }]
    }]

Recommendation