ModelWorks logoModelWorks
JSON TransformArray

slice

Extract a contiguous portion of an array

slice

Returns the slice of an array between start (inclusive) and end (exclusive). Both indices are clamped to the array length, so out-of-range values are safe.

Options

OptionTypeRequiredDefaultDescription
startintegerYesInclusive start index. Negatives floor to 0.
endintegerNoarray lengthExclusive end index. Negatives floor to 0.

Example

Input

JSON
["a", "b", "c", "d", "e"]

Operation

JSON
{ "type": "slice", "options": { "start": 1, "end": 4 } }

Output

JSON
["b", "c", "d"]

In a Circuit Step

JSON
{
  "name": "take_window",
  "description": "Take messages 1..3 from the conversation",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ messages }}",
    "operations": [
      { "type": "slice", "options": { "start": 1, "end": 4 } }
    ]
  },
  "outputs": [
    {
      "name": "windowed_messages",
      "description": "A 3-message slice of the input",
      "value": "${{ take_window.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with slice: expected array if the input value is not an array.
  • start is clamped to [0, len] and end defaults to len, so { "start": 100 } returns [] rather than panicking.
  • Negative start / end values are floored to 0. There is no Python-style "from the end" support.
  • slice is non-destructive — it returns a new array and the input is left untouched.
On this page

On this page