Miscellaneous Utilities

Flatten Array

Flatten Array converts nested arrays into a single-level array, removing all nesting regardless of depth. Access via MCP in Cursor or Windsurf, or call GET /v1/misc/flatten with your nested array data. Returns `[1,2,3,4,5]` from `[[1,2],[3,[4,5]]]`. Handles mixed data types and preserves original element order deterministically.

API Endpoint

GET /v1/misc/flatten

Code Examples

curl "https://tinyfn.io/v1/misc/flatten" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/misc/flatten', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/misc/flatten',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's miscellaneous tools:

{
  "mcpServers": {
    "tinyfn-misc": {
      "url": "https://tinyfn.io/mcp/misc",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I flatten a deeply nested array with mixed data types?

Pass any nested array structure to the flatten endpoint — it handles unlimited nesting depth and preserves strings, numbers, booleans, and null values in their original order.

Can MCP agents use array flattening for data preprocessing?

Yes, AI agents in Cursor or Claude Code can call this tool to normalize nested data structures before processing, especially useful for cleaning API responses or user input.

Does flatten preserve the original data types of elements?

Absolutely — only the array structure changes. Numbers stay numbers, strings stay strings, and the relative order of all elements is maintained.

What happens when I flatten an array that's already flat?

It returns the same array unchanged. The tool safely processes any input without errors, making it ideal for conditional flattening workflows.

How does this differ from JavaScript's Array.flat() method?

This tool flattens to unlimited depth by default (like Array.flat(Infinity)), works server-side for any language, and provides consistent results across different environments.

Try Flatten Array Now

Get your free API key and start using Flatten Array in seconds.

Get Free API Key