JSON TransformArray
replaceAt
Replace the element at a specific index
replaceAt
Overwrites the element at index with value. If the index is out of range the array is returned unchanged.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
index | integer | Yes | — | Zero-based index of the element to replace. |
value | any | Yes | — | Replacement value (any JSON type). |
Example
Input
["a", "b", "c"]Operation
{ "type": "replaceAt", "options": { "index": 1, "value": "BB" } }Output
["a", "BB", "c"]In a Circuit Step
{
"name": "swap_second_message",
"description": "Replace the second message in the conversation",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ messages }}",
"operations": [
{
"type": "replaceAt",
"options": {
"index": 1,
"value": { "role": "user", "content": "${{ input.replacement_text }}" }
}
}
]
},
"outputs": [
{
"name": "patched_messages",
"description": "Conversation with element at index 1 replaced",
"value": "${{ swap_second_message.output.transformed_result }}"
}
]
}Notes & gotchas
- Errors with
replaceAt: expected arrayif the input is not an array. - An out-of-range
indexis silently ignored — the array passes through unchanged. There is no error or growth. valueis not selector-evaluated byreplaceAtitself. To inject a selector value, place the selector string intovalueupstream (outer selector resolution) or usemapfor conditional replacement.- To replace by condition rather than index, see
replaceMatching.