JSON TransformArray
flatten
Flatten nested arrays up to a configurable depth
flatten
Flattens nested arrays. With depth: 1 (the default) only one level is unwrapped; deeper nesting is preserved.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
depth | integer | No | 1 | How many levels to flatten. 0 returns input wrapped as-is. |
Example
Input
[[1, 2], [3, [4, 5]], 6]Operation (depth 1)
{ "type": "flatten", "options": { "depth": 1 } }Output
[1, 2, 3, [4, 5], 6]Operation (depth 2)
{ "type": "flatten", "options": { "depth": 2 } }Output
[1, 2, 3, 4, 5, 6]In a Circuit Step
{
"name": "flatten_pages",
"description": "Flatten a paginated list of items into a single array",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ pages }}",
"operations": [
{ "type": "flatten", "options": { "depth": 1 } }
]
},
"outputs": [
{
"name": "all_items",
"description": "All items from all pages, in order",
"value": "${{ flatten_pages.output.transformed_result }}"
}
]
}Notes & gotchas
- Unlike most array operations,
flattendoes not error on non-array input. A scalar input becomes[input]. depth: 0returns[input]unchanged (no flattening occurs).- Each level descends through
Value::Arrayonly; objects are treated as opaque leaves and not flattened. - The output is always an array, even when starting from a scalar.