List functions list-functions
List functions enable you to manipulate and work with collections of values within your journey expressions. These functions are essential for filtering, sorting, transforming, and analyzing arrays and lists in your customer journeys.
Use list functions when you need to:
- Filter and extract specific items from collections based on criteria (filter, getListItem)
- Sort and organize list elements in ascending or descending order (sort)
- Remove duplicates and get unique values from lists (distinct, distinctWithNull)
- Check if values exist within collections (in)
- Limit the number of items returned from a list (limit)
- Get the size of a list (listSize) or transform lists into different formats (serializeList)
- Perform set operations like finding common elements between lists (intersect), combining lists (mergeLists), or subtracting one list from another (differenceLists)
List functions provide powerful tools for working with complex data structures, enabling sophisticated data manipulation and conditional logic based on collection contents.
differenceLists differenceLists
Returns the items of the first list that are not present in the second list (set difference: list 1 - list 2). Null entries are skipped. The result always removes duplicate values and preserves the insertion order of the first list.
differenceLists(<parameters>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| list 1 | listString, listInteger, listDecimal, listBoolean, listDuration, listDateTime, listDateTimeOnly, or listDateOnly | List to subtract from. |
| list 2 | Same type as list 1. | List of items to remove from list 1. |
differenceLists(listString,listString): listString
differenceLists(listInteger,listInteger): listInteger
differenceLists(listDecimal,listDecimal): listDecimal
differenceLists(listBoolean,listBoolean): listBoolean
differenceLists(listDuration,listDuration): listDuration
differenceLists(listDateTime,listDateTime): listDateTime
differenceLists(listDateTimeOnly,listDateTimeOnly): listDateTimeOnly
differenceLists(listDateOnly,listDateOnly): listDateOnly
| code language-json |
|---|
|
Returns ['a','c'].
| code language-json |
|---|
|
Returns ['a','b'].
| code language-json |
|---|
|
Returns [].
distinct distinct
Returns the distinct values or objects of a given list. Null entries are ignored.
distinct(<parameters>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly, or listObject | List to process. For listObject, it must be a field reference. |
| keyAttributeName | string | This parameter is optional and only for listObject. If the parameter is not provided, an object is considered as duplicated if all the attributes have the same values. Otherwise, an object is considered as duplicated if the given attribute has the same value. |
distinct(<listInteger>)
Returns a list of integers.
distinct(<listDecimal>)
Returns a list of decimals.
distinct(<listString>)
Returns a list of strings.
distinct(<listDateTimeOnly>)
Returns a list of datetimes without considering time zone.
distinct(<listDateTime>)
Returns a list of datetimes.
distinct(<listDateOnly>)
Returns a list of dates.
distinct(<listBoolean>)
Returns a list of booleans.
distinct(<listDuration>)
Returns a list of durations.
distinct(<listObject>)
distinct(<listObject>,<string>)
Returns a list of objects.
distinct([10,2,10,null])
Returns [10, 2].
distinctWithNull distinctWithNull
Returns the distinct values or objects of a given list. If the list has at least one null entry, a null entry will be present in the returned list.
distinctWithNull(<parameters>)| table 0-row-3 1-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly | List to process. |
distinctWithNull(<listInteger>)
Returns a list of integers.
distinctWithNull(<listDecimal>)
Returns a list of decimals.
distinctWithNull(<listString>)
Returns a list of strings.
distinctWithNull(<listDateTimeOnly>)
Returns a list of datetimes without considering time zone.
distinctWithNull(<listDateTime>)
Returns a list of datetimes.
distinctWithNull(<listDateOnly>)
Returns a list of dates.
distinctWithNull(<listBoolean>)
Returns a list of booleans.
distinctWithNull(<listDuration>)
Returns a list of durations.
distinctWithNull([10,2,10,null])
Returns [10, 2, null]
Note: The parameter <listObject> is not supported in this function.
filter filter
Returns a listObject with objects having the key attribute matching one of the given key values.
filter(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToFilter | listObject | list of objects, to be filtered. It must be a field reference. |
| keyAttributeName | string | attribute name in the objects of the given list, used as key for filtering |
| keyValueList | list | array of key values for filtering |
filter(listObject, string, listString)
filter(listObject, string, listInteger)
filter(listObject, string, listDecimal)
filter(listObject, string, listDateTime)
filter(listObject, string, listDateTimeOnly)
filter(listObject, string, listDateOnly)
filter(listObject, string, listDuration)
filter(listObject, string, listBoolean)
Returns a listObject.
Here is an example of a payload passed in an incoming event “myevent”:
| code language-json |
|---|
|
You can use the following expression:
| code language-json |
|---|
|
Returns a listObject containing the two objects with “product2” and “product3” as id.
getListItem getListItem
Returns the item of the list at the given index.
getListItem(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 6-row-2 7-row-2 8-row-2 9-row-2 | |
|---|---|
| Parameter | Type |
| list | listString |
| list | listBoolean |
| list | listInteger |
| list | listDecimal |
| list | listDuration |
| list | listDateTime |
| list | listDateTimeOnly |
| list | listDateOnly |
| index | integer |
getListItem(<listInteger>,<index>)
Returns an integer.
getListItem(<listDecimal>,<index>)
Returns a decimal.
getListItem(<listString>,<index>)
Returns a string.
getListItem(<listDateTimeOnly>,<index>)
Returns a datetime without considering time zone.
getListItem(<listDateTime>,<index>)
Returns a datetime.
getListItem(<listDateOnly>,<index>)
Returns a list of dates.
getListItem(<listBoolean>,<index>)
Returns a boolean.
getListItem(<listDuration>,<index>)
Returns a duration.
getListItem([10, 2, 3], 1)
Returns “2”
getListItem(["A", "B", "C"], 2)
Returns “C”
Examples with an event field ‘event.appVersion’ with value: “20.45.2.3434”
split(@event{event.appVersion}, "\\.")
Returns ["20", "45", "2", "3434"]
getListItem(split(@event{event.appVersion}, "\\."), 0)
Returns “20”
in in
Checks if the first argument value is in the list. The check is performed through an Equal on each argument value. It returns true if the argument value is found, false otherwise.
The type of the <expression> must match with items of the list. Types of items of the list, as a reminder, must match with each other.
in(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 6-row-2 7-row-2 8-row-2 9-row-2 10-row-2 11-row-2 12-row-2 13-row-2 14-row-2 15-row-2 | |
|---|---|
| Parameter | Type |
| String | String |
| Boolean | Boolean |
| Integer | Integer |
| Decimal | Decimal |
| Duration | Duration |
| DateTime | DateTime |
| DateTimeOnly | DateTimeOnly |
| List | listString |
| List | listBoolean |
| List | listInteger |
| List | listDecimal |
| List | listDuration |
| List | listDateTime |
| List | listDateTimeOnly |
| List | listDateOnly |
in(<integer>,<listInteger>)
in(<decimal>,<listDecimal>)
in(<string>,<listString>)
in(<boolean>,<listBoolean>)
in(<dateTimeOnly>,<listDateTimeOnly>)
in(<dateTime>,<listDateTime>)
in(<dateOnly>,<listDateOnly>)
in(<duration>,<listDuration>)
Return a boolean.
in(4,[4,5,3,4])
Returns true.
in(8,[4,5,3,4])
Returns false.
in(#{ExperiencePlatform.ProfileFieldGroup.profile.person.gender}, ["male"])
intersect intersect
Returns the common values in the two input lists. If one of the two lists is null, returns an empty list.
intersect(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| list 1 | list |
| list 2 | list |
intersect(listString,listString): listString
intersect(listDecimal,listDecimal): listDecimal
intersect(listInteger,listInteger): listInteger
intersect(listDateTime,listDateTime): listDateTime
intersect(listDateTimeOnly,listDateTimeOnly): listDateTimeOnly
intersect(listDateOnly,listDateOnly): listDateOnly
intersect(listDuration,listDuration): listDuration
intersect(listBoolean,listBoolean): listBoolean
Returns a list.
| code language-json |
|---|
|
Returns [“sports”, “news”]
| code language-json |
|---|
|
Returns common items between profile attributes and given list of categories.
| code language-json |
|---|
|
Returns common items between profile attributes and given event field.
limit limit
Returns the first or last N elements of a list.
limit(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly, or listObject | List to consider. For listObject, it must be a field reference. |
| numberOfItems | integer | Number of items to be returned from the given list. |
| firstOrLastItems | boolean | This parameter is optional (true by default). true returns the first items. false returns the last items. |
limit(<listString>,<integer>)
limit(<listString>,<integer>,<boolean>)
Returns a list of strings.
limit(<listInteger>,<integer>)
limit(<listInteger>,<integer>,<boolean>)
Returns a list of integers.
limit(<listDecimal>,<integer>)
limit(<listDecimal>,<integer>,<boolean>)
Returns a list of decimals.
limit(<listBoolean>,<integer>)
limit(<listBoolean>,<integer>,<boolean>)
Returns a list of booleans.
limit(<listDateOnly>,<integer>)
limit(<listDateOnly>,<integer>,<boolean>)
Returns a list of dates.
limit(<listDateTimeOnly>,<integer>)
limit(<listDateTimeOnly>,<integer>,<boolean>)
Returns a list of datetimes without considering time zone.
limit(<listDateTime>,integer>)
limit(<listDateTime>,<integer>,<boolean>)
Returns a list of datetimes.
limit(<listDuration>,<integer>)
limit(<listDuration>,<integer>,<boolean>)
Returns a list of durations.
limit(<listObject>,<integer>)
limit(<listObject>,<integer>,<boolean>)
Returns a list of objects.
limit(["A", "B", "C", "D", "E"], 3)
Returns ["A","B","C"].
limit(["A", "B", "C", "D", "E"], 3, false)
Returns ["C","D","E"].
listSize listSize
Counts the number of elements in the list.
listSize(<parameters>)| table 0-row-3 1-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly, or listObject | List to process. For listObject, it must be a field reference. A listObject cannot contain null object. |
listSize(<listInteger>)
listSize(<listDecimal>)
listSize(<listString>)
listSize(<listBoolean>)
listSize(<listDateTimeOnly>)
listSize(<listDateTime>)
listSize(<listDateOnly>)
listSize(<listDuration>)
Return an integer.
listSize(<listObject>)
listSize([10,2,3])
Returns 3.
listSize(@event{my_event.productListItems})
Returns the number of objects in the given array of objects (listObject type).
mergeLists mergeLists
Combines two lists. When deduplicate is true, returns the union of the two lists with duplicate values removed. When deduplicate is false, returns the concatenation of the two lists (list 1’s items followed by list 2’s items), keeping duplicates. Null entries are skipped.
Note: The deduplicate parameter must be a literal true or false, not a dynamic boolean expression.
mergeLists(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| list 1 | listString, listInteger, listDecimal, listBoolean, listDuration, listDateTime, listDateTimeOnly, or listDateOnly | First list. Its items are added first to the result. |
| list 2 | Same type as list 1. | Second list. Its items are added after list 1’s items. |
| deduplicate | boolean literal | true returns the union of both lists with duplicates removed. false returns the concatenation of both lists, keeping duplicates. Must be a literal true or false. |
mergeLists(listString,listString,boolean): listString
mergeLists(listInteger,listInteger,boolean): listInteger
mergeLists(listDecimal,listDecimal,boolean): listDecimal
mergeLists(listBoolean,listBoolean,boolean): listBoolean
mergeLists(listDuration,listDuration,boolean): listDuration
mergeLists(listDateTime,listDateTime,boolean): listDateTime
mergeLists(listDateTimeOnly,listDateTimeOnly,boolean): listDateTimeOnly
mergeLists(listDateOnly,listDateOnly,boolean): listDateOnly
| code language-json |
|---|
|
Returns ['a','b','c'].
| code language-json |
|---|
|
Returns ['a','b','b','c'].
serializeList serializeList
Converts a given list (any type except listObject) into a string.
serializeList(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly | List to convert into a string. |
| separator | string | Separator between each list element in the output string. |
| addQuotes | boolean | This parameter indicates if each element in the output string should include quotes (true) or not (false). |
serializeList(<listInteger>,<string>,<boolean>)
serializeList(<listDecimal>,<string>,<boolean>)
serializeList(<listString>,<string>,<boolean>)
serializeList(<listBoolean>,<string>,<boolean>)
serializeList(<listDateTimeOnly>,<string>,<boolean>)
serializeList(<listDateTime>,<string>,<boolean>)
serializeList(<listDateOnly>,<string>,<boolean>)
serializeList(<listDuration>,<string>,<boolean>)
Return a string.
serializeList(["Hello","World"], " ", false)
Returns “Hello World”.
serializeList(["Hello", "World"], ",", true)
Returns ““Hello”,“World””.
sort sort
Sorts a list of values or objects in the natural order.
sort(<parameters>)| table 0-row-3 1-row-3 2-row-3 3-row-3 | ||
|---|---|---|
| Parameter | Type | Description |
| listToSort | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly, or listObject | List to sort out. For listObject, it must be a field reference. |
| keyAttributeName | string | This parameter is only for listObject. The attribute name in the objects of the given list is used as key for sorting. |
| sortingOrder | boolean | Ascending (true) or descending (false) |
sort(<listInteger>,<boolean>)
Returns a list of integers.
sort(<listDecimal>,<boolean>)
Returns a list of decimals.
sort(<listString>,<boolean>)
Returns a list of strings.
sort(<listDateTimeOnly>,<boolean>)
Returns a list of datetimes without considering time zone.
sort(<listDateTime>,<boolean>)
Returns a list of datetimes.
sort(<listDateOnly>,<boolean>)
Returns a list of dates.
sort(<listBoolean>,<boolean>)
Returns a list of booleans.
sort(<listObject>,<string>,<boolean>)
Returns a list of objects.
sort(["A", "C", "B"], true)
Returns ["A","B","C"].
sort([1, 3, 2], false)
Returns [3, 2, 1].
sort(@event{my_event.productListItems}, "SKU", true)
Returns the listObject ordered by SKU attribute (ascending order)
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all list functions available in AJO journey expressions, covering how to filter, sort, deduplicate, check membership, limit, serialize, merge, subtract, and find intersections of lists and arrays.
Intents:
- Remove duplicate values from a list using
distinct(ignoring nulls) ordistinctWithNull(preserving nulls) - Filter a listObject to return only objects matching specific key values using
filter - Retrieve an element at a specific index from a list using
getListItem - Check whether a value exists in a list using
in - Find common elements between two lists using
intersect - Combine two lists, with or without deduplication, using
mergeLists - Subtract one list from another (set difference) using
differenceLists - Return the first or last N elements of a list using
limit - Count the total number of elements in a list using
listSize - Convert a list to a delimited string using
serializeList - Sort a list in ascending or descending order using
sort
Glossary:
- listObject: A list of complex objects that must be a field reference; cannot contain null objects (product-specific)
- keyAttributeName: An optional string parameter used with
distinct,filter, andsortto identify which object attribute to use for deduplication, filtering, or sorting (product-specific) - intersect: A set operation returning only the elements present in both input lists
- mergeLists: A set operation returning the union (deduplicated) or concatenation (with duplicates) of two lists, depending on the
deduplicateparameter (product-specific) - differenceLists: A set operation returning the items of the first list that are not present in the second list (product-specific)
Guardrails:
distinctWithNulldoes not support the<listObject>parameter typefilterrequires the listObject parameter to be a field reference, not an inline literallistSizeon a listObject requires the list to be a field reference; a listObject cannot contain null objectsserializeListdoes not support thelistObjecttypemergeListsanddifferenceListsonly support scalar list types (string, integer, decimal, boolean, dateTime, dateTimeOnly, dateOnly, duration);listObjectis not supportedmergeLists’sdeduplicateparameter must be a literaltrue/false, not a dynamic boolean expressiondifferenceListsalways deduplicates its result; there is no option to keep duplicates
Terminology:
- Canonical name: List functions — Acronym: none — variants: collection functions, array functions
- Synonyms: “listSize” = “count list elements”; “serializeList” = “join list to string”
- Do not confuse: “distinct” (ignores nulls) ≠ “distinctWithNull” (preserves null as a distinct value)
- Do not confuse: “limit” with third parameter
true(returns first N items) ≠ “limit” withfalse(returns last N items) - Do not confuse: “intersect” (common elements between two lists) ≠ “filter” (elements matching specific key values)
- Do not confuse: “mergeLists” (combines two lists, union or concatenation) ≠ “differenceLists” (subtracts one list from another) ≠ “intersect” (common elements only)
FAQ:
- Q: How do I get the first 3 items of a list? — Use
limit(myList, 3)orlimit(myList, 3, true); the default is to return the first items. - Q: How do I get the last 3 items of a list? — Use
limit(myList, 3, false). - Q: What is the difference between
distinctanddistinctWithNull? —distinctignores null values and excludes them from the result;distinctWithNulltreats null as a distinct value and includes one null entry if any nulls are present. - Q: Can I filter a list of strings with
filter? — No,filteronly works onlistObject; for scalar lists useinordistinctfor deduplication. - Q: How do I check if a value is in a list? — Use
in(value, myList), which returns true if the value is found in the list. - Q: Can I sort a listObject by a specific attribute? — Yes, use
sort(@event{...}, "attributeName", true)where the second parameter is the attribute name and the third is the sort direction (true = ascending). - Q: How do I combine two lists and remove duplicates? — Use
mergeLists(list1, list2, true). - Q: How do I combine two lists but keep duplicate values? — Use
mergeLists(list1, list2, false). - Q: How do I find the items in one list that are not in another? — Use
differenceLists(list1, list2), which returns the items oflist1not present inlist2. - Q: What is the difference between
intersectanddifferenceLists? —intersectreturns items common to both lists;differenceListsreturns items in the first list that are absent from the second list.