When you're building pages that pull data from multiple sources or work with complex nested structures, you need tools to organize arrays. Sometimes you need to combine separate arrays into one. Other times you need to take nested arrays and flatten them into a simple list.
CONCAT and FLATTEN both work with combining arrays, but they solve different problems. Understanding when to use each will help you prepare clean, usable data for your pages.
What CONCAT does
CONCAT joins two or more arrays end-to-end. It takes separate arrays and combines them into a single array, preserving all the elements from each source in the order you specify.
Think of it like stacking boxes: you take the contents of the first box, add the contents of the second box, then the third. Everything ends up in one collection.
CONCAT basic syntax
CONCAT takes multiple arrays as arguments:
CONCAT(array1, array2, array3, ...)CONCAT example: Unify departmental user lists
Let's say you have user lists (arrays) from three different departments:
{
"security": [
"Alice",
"Bob"
],
"engineering": [
"Charile",
"Diana"
],
"operations": [
"Eve"
]
}We want to combine them into one list. To do so, we utilize CONCAT:
CONCAT(action_name.security, action_name.engineering, action_name.operations)The output:
[
"Alice",
"Bob",
"Charile",
"Diana",
"Eve"
]All five users are now in one array, ready for input into a page dropdown, for example.
What FLATTEN does
FLATTEN takes nested arrays (arrays within arrays) and collapses them into a single, one-dimensional array. If you have multiple levels of nesting, FLATTEN removes all the layers and gives you one flat list.
Think of it like unpacking nested containers: if you have boxes inside boxes inside boxes, FLATTEN opens everything and lays all the items out in a single row.
FLATTEN basic syntax
FLATTEN takes one nested array and simplifies it:
FLATTEN(array)FLATTEN example: Unify alert lists
Let's say you've collected alert IDs from multiple systems, and each system returned an array:
{
"alerts": [
[
"A-001",
"A-002"
],
[
"B-100",
"B-101",
"B-102"
],
[
"C-500"
]
]
}This is a nested structure; an array containing three arrays. To flatten it:
FLATTEN(action_name.alerts)The output:
[
"A-001",
"A-002",
"B-100",
"B-101",
"B-102",
"C-500"
]Now you have a simple, one-dimensional array with all six alert IDs.