ModelWorks logoModelWorks
JSON TransformArray

chunk

Split an array into fixed-size chunks

chunk

Splits an array into successive chunks of size. The final chunk may be shorter if the array length isn't a multiple of size.

Options

OptionTypeRequiredDefaultDescription
sizeintegerYesChunk size (must be > 0).

Example

Input

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

Operation

JSON
{ "type": "chunk", "options": { "size": 3 } }

Output

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

In a Circuit Step

JSON
{
  "name": "batch_records",
  "description": "Split records into batches of 50 for downstream processing",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ records }}",
    "operations": [
      { "type": "chunk", "options": { "size": 50 } }
    ]
  },
  "outputs": [
    {
      "name": "record_batches",
      "description": "Records grouped into batches of up to 50 each",
      "value": "${{ batch_records.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with chunk: expected array if the input is not an array.
  • A size of 0 will panic at the slice level — always pass a positive integer.
  • The trailing chunk is included as-is even when shorter than size. There is no padding option; pad upstream with push if you need fixed-size groups.
  • The output is an array of arrays. Pair with map to apply a transformation per chunk.
On this page

On this page