Categories

Chunk Array

Split array into chunks of specified size using lodash _.chunk

Split any array into smaller chunks (sub-arrays) of a specified size.

Features:

  • Accepts JSON arrays (numbers, strings, objects, or mixed types)
  • Customizable chunk size (1-100 elements)
  • Uses lodash _.chunk for reliable array processing
  • Preserves array element types

Examples:

  • Input: [1, 2, 3, 4, 5], Size: 2 → [[1, 2], [3, 4], [5]]
  • Input: ["a", "b", "c", "d", "e"], Size: 3 → [["a", "b", "c"], ["d", "e"]]
  • Input: [1, "a", 2, "b"], Size: 2 → [[1, "a"], [2, "b"]]

Use Cases:

  • Batch Processing: Process arrays in batches for API calls
  • Pagination: Split data into page-sized chunks
  • Data Organization: Group related array elements
  • Memory Management: Process large arrays in smaller pieces

Enter a valid JSON array to chunk

Number of elements per chunk (1-100)

Key Facts

Category
Data Processing
Input Types
textarea, number
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Chunk Array tool splits any JSON array into smaller chunks of a specified size using the reliable lodash _.chunk function. It supports arrays of numbers, strings, objects, or mixed types, with customizable chunk sizes from 1 to 100 elements.

When to Use

  • When you need to process large arrays in batches for API calls to avoid rate limits or memory issues.
  • When implementing pagination by dividing data into fixed-size chunks for display in web applications.
  • When organizing related array elements into groups for efficient data analysis or management.

How It Works

  • Enter a valid JSON array into the input textarea, such as [1, 2, 3, 4, 5] or ["a", "b", "c"].
  • Specify the chunk size using the number input, which must be between 1 and 100 elements per chunk.
  • The tool applies the lodash _.chunk function to split the array into sub-arrays based on the size.
  • Output is provided as a JSON array of arrays, where each inner array is a chunk from the original input.

Use Cases

Batch API Processing: Split large datasets like user IDs into chunks to send multiple API requests in batches.
Data Pagination: Divide a list of items, such as products or articles, into page-sized chunks for UI display.
Memory-Efficient Processing: Handle large arrays by processing one chunk at a time to reduce memory usage.

Examples

1. Batch Processing for API Calls

Software Developer
Background
A developer has an array of 500 user IDs that need to be sent to an API with a rate limit of 100 requests per batch.
Problem
The array must be split into manageable chunks to comply with the API's batch size restriction.
How to Use
Enter the array of user IDs, e.g., [1, 2, 3, ..., 500], and set the chunk size to 100.
Outcome
The array is split into 5 chunks of 100 IDs each, allowing sequential API calls without exceeding limits.

2. Pagination for Product Listings

Background
An e-commerce site displays 200 products, but the frontend shows only 20 items per page for better user experience.
Problem
The product array needs to be divided into chunks to create separate pages for navigation.
How to Use
Input the product array, such as [{"id": 1, "name": "Product A"}, ...], and specify a chunk size of 20.
Outcome
The array is chunked into 10 sub-arrays, each representing a page of 20 products for display.

Try with Samples

json

Related Hubs

FAQ

What types of arrays can I input?

You can input any valid JSON array, including numbers, strings, objects, or mixed types.

What is the default chunk size?

The default chunk size is 2 elements per chunk.

Can I chunk arrays with nested objects?

Yes, the tool preserves element types, so nested objects are handled correctly within chunks.

Is there a limit to the array size I can process?

While there's no strict limit, very large arrays may depend on your browser or system memory for processing.

How is the output formatted?

The output is a JSON array where each element is a sub-array (chunk) containing a portion of the original array.

API Documentation

Request Endpoint

POST /en/api/tools/chunk-array

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a valid JSON array to chunk
size number No Number of elements per chunk (1-100)

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-chunk-array": {
      "name": "chunk-array",
      "description": "Split array into chunks of specified size using lodash _.chunk",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=chunk-array",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]