Resources »

Solutions Hub »

Automations »

Batch list items into sets

Using |batch filter

The |batch filter divides a list into smaller sets. These sets can be specified to a size, incomplete sets can be filled with a default value, and original array keys can be preserved or not.

  • 
    start:
      set:
        items@json: [1,2,3,4,5,6,7,8,9,10]
      return:
        batches: {{items|batch(size=3, fill=-1, preserve_keys=false)|json_encode}}
    
    
  • 
    __return:
      batches: '[[1,2,3],[4,5,6],[7,8,9],[10,-1,-1]]'