JSON TransformArray
insertAt
Insert one or more elements at a specific index
insertAt
Inserts items into the array starting at index, shifting existing elements to the right. If items is itself an array, the elements are inserted individually (spread); otherwise items is inserted as a single element.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
index | integer | Yes | — | Zero-based insertion index. Clamped to array length. |
items | any | Yes | — | Item or array of items to insert. Selectors resolved. |
Example
Input
["a", "d"]Operation
{ "type": "insertAt", "options": { "index": 1, "items": ["b", "c"] } }Output
["a", "b", "c", "d"]In a Circuit Step
{
"name": "inject_context_block",
"description": "Insert two context messages just after the system prompt",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ messages }}",
"operations": [
{
"type": "insertAt",
"options": {
"index": 1,
"items": [
{ "role": "user", "content": "${{ input.context_a }}" },
{ "role": "user", "content": "${{ input.context_b }}" }
]
}
}
]
},
"outputs": [
{
"name": "messages_with_context",
"description": "Conversation with two context messages inserted at index 1",
"value": "${{ inject_context_block.output.transformed_result }}"
}
]
}Notes & gotchas
- Errors with
insertAt: expected arrayif the input is not an array. indexis clamped to the current length, soindex: 999appends rather than failing.- When
itemsis an array, elements are inserted in order:insertAt(1, ["b","c"])on["a","d"]yields["a","b","c","d"], not["a","c","b","d"]. itemsis fully selector-evaluated, including nested entries.