ModelWorks logoModelWorks
JSON TransformArray

push

Append elements to the end of an array

push

Adds one or more items to the end of an array. If items is itself an array, its elements are appended individually (spread); otherwise the value is appended as a single element.

Options

OptionTypeRequiredDefaultDescription
itemsanyYesItem or array of items to append. Selectors inside are resolved first.

Example

Input

JSON
[1, 2, 3]

Operation

JSON
{ "type": "push", "options": { "items": [4, 5] } }

Output

JSON
[1, 2, 3, 4, 5]

In a Circuit Step

JSON
{
  "name": "append_followup",
  "description": "Append a follow-up message to the conversation",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ messages }}",
    "operations": [
      {
        "type": "push",
        "options": {
          "items": [
            { "role": "user", "content": "${{ input.followup }}" }
          ]
        }
      }
    ]
  },
  "outputs": [
    {
      "name": "extended_messages",
      "description": "Messages with follow-up appended",
      "value": "${{ append_followup.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with push: expected array if the input is not an array.
  • Pushing a non-array value appends it as a single element: push({ "items": "hello" }) on ["a"] yields ["a", "hello"].
  • items is fully selector-evaluated before append — "items": "${{ input.tail }}" works, including selectors nested inside an items array.
  • To wrap a single array as one element rather than spreading it, use insertAt at the end index, or wrap it manually: "items": [["nested", "array"]].
On this page

On this page