Collections#
CEL checks membership, searches, and filters lists and maps with built-in operators and macros. Examples on this page use this message:
{
"id": "ord-123",
"customer": "alice@example.com",
"tags": ["express", "gift-wrapped"],
"items": [
{"name": "Laptop", "category": "electronics", "price": 999, "quantity": 1},
{"name": "Cable", "category": "accessories", "price": 29, "quantity": 3}
],
"status": "pending"
}
Membership and access#
in checks whether a value exists in a list.
size() returns the number of elements.
Index with [] to access individual elements.
Access nested fields on list elements with dot notation.
Searching with exists()#
exists() tests whether any element satisfies a condition.
Combine multiple checks in the predicate.
Checking all with all()#
all() tests whether every element satisfies a condition.
Filtering with filter()#
filter() narrows a list to elements that match a condition.
order.items.filter(i, i.price > 100)
// result: [{"name": "Laptop", "category": "electronics", "price": 999, "quantity": 1}] (list)
order.items.filter(i, i.category == "electronics")
// result: [{"name": "Laptop", "category": "electronics", "price": 999, "quantity": 1}] (list)