Automate Data Processing with n8n's Set and Split Out Tools

Streamline your data workflows using n8n's Set and Split Out tools to efficiently manage and transform data. This workflow is ideal for business teams looking to automate repetitive tasks. Requires 0 accounts: simply set up your n8n instance. Experience enhanced productivity by reducing manual data handling, saving your team hours each week.

1 Trigger
22,625 views13 nodesJun 2025Nathan Foster

Categories

Miscellaneous

Quick Actions

Copy or download to import into your n8n instance

Workflow JSON
{
  "meta": {
    "instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0"
  },
  "nodes": [
    {
      "id": "e36b580a-9314-453c-88d6-7ffb948e79a8",
      "name": "1. Sample Data",
      "type": "n8n-nodes-base.set",
      "position": [
        500,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "38ce3db6-ce1d-4091-9645-39e674ad1782",
              "name": "users",
              "type": "array",
              "value": "=[{\"firstName\":\"Alice\",\"lastName\":\"Smith\",\"birthDate\":\"1990-05-15\"},{\"firstName\":\"Bob\",\"lastName\":\"Jones\",\"birthDate\":\"1985-11-22\"},{\"firstName\":\"Charlie\",\"lastName\":\"Brown\",\"birthDate\":\"2001-02-10\"}, {\"firstName\":\"Alex\",\"lastName\":\"Garcia\",\"birthDate\":\"1995-07-30\"}]"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d77a1d9a-376a-451c-9fc3-174a60fb787a",
      "name": "2. Split Out Users",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        720,
        480
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "users"
      },
      "typeVersion": 1
    },
    {
      "id": "39ab2c6f-11ce-4e1e-a6c7-327d758f6d0c",
      "name": "3. Process Each User",
      "type": "n8n-nodes-base.code",
      "position": [
        1040,
        480
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// This code runs for EACH user individually.\n\n// 1. Get the data for the current item\nconst user = $input.item.json;\n\n// 2. Perform operations\nconst fullName = `${user.firstName} ${user.lastName}`;\n\nconst birthDate = new Date(user.birthDate);\nconst ageDiffMs = Date.now() - birthDate.getTime();\nconst ageDate = new Date(ageDiffMs);\nconst age = Math.abs(ageDate.getUTCFullYear() - 1970);\n\nconsole.log(`Processing user: ${fullName}, Age: ${age}`);\n\n// 3. Return the new data, keeping the original fields\nreturn {\n  ...user, // This keeps the original data (firstName, lastName, etc.)\n  fullName: fullName,\n  age: age\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "9f4aa08e-f15f-4215-843c-87997e6d6cff",
      "name": "5. Calculate Average Age",
      "type": "n8n-nodes-base.code",
      "position": [
        1840,
        480
      ],
      "parameters": {
        "jsCode": "// This code runs only ONCE for ALL users.\n\n// 1. Get all items from the previous node\nconst allUsers = $items();\n\n// 2. Perform an aggregation\nconst totalAge = allUsers.reduce((sum, item) => {\n  return sum + item.json.age;\n}, 0);\n\nconst userCount = allUsers.length;\nconst averageAge = totalAge / userCount;\n\nconsole.log(`Calculated average age for ${userCount} users.`);\n\n// 3. Return a single new item with the result\nreturn [\n  {\n    json: {\n      totalUsers: userCount,\n      averageAge: parseFloat(averageAge.toFixed(2)) // Format to 2 decimal places\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "2e7f0710-0b4a-450e-8e87-591c5324f5c7",
      "name": "4. Fetch External Data (Advanced)",
      "type": "n8n-nodes-base.code",
      "position": [
        1440,
        480
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// ADVANCED: This code calls an external API for each user.\n\n// 1. Get the data for the current item\nconst user = $input.item.json;\n\n// 2. Use a helper function to make an HTTP request\n// We'll use a free API to guess the gender based on the first name.\nconst url = `https://api.genderize.io?name=${user.firstName}`;\n\nconsole.log(`Fetching external data for ${user.firstName} from ${url}`)\n\n// this.helpers.httpRequest is a powerful built-in function.\n// We use 'await' because it's an asynchronous operation.\nconst response = await this.helpers.httpRequest({ url: url, json: true });\n\n// 3. Return the original data merged with the new API data\nreturn {\n  ...user, // Keep all existing data (fullName, age, etc.)\n  gender: response.gender,\n  genderProbability: response.probability\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "809e91c4-02b6-4d12-b8f0-e9cd96d92c24",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        240
      ],
      "parameters": {
        "color": 5,
        "width": 440,
        "height": 420,
        "content": "#### ▶️ STARTING POINT: Sample Data\n\nThese nodes prepare our data for the tutorial.\n\n1.  **`1. Sample Data`**: Creates a list of users. Feel free to edit the values here to experiment!\n2.  **`2. Split Out Users`**: Splits the list into multiple items, one for each user. This is necessary so the next Code nodes can process them one by one."
      },
      "typeVersion": 1
    },
    {
      "id": "bc8ec047-8595-4a07-8422-09779f8490c0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        900,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 380,
        "height": 580,
        "content": "#### ⚙️ LESSON 1: Processing Each Item\n\nThis node is in **\"Run Once for Each Item\"** mode. It executes once for every user.\n\n**Goal:** Enrich each user's data.\n\n**Key Concepts:**\n*   `$input.item.json`: Accesses the data of the *current* item being processed.\n*   `return { ... }`: Returns an object that becomes the new output for the item. The `...user` trick keeps the original data.\n\n\nRun the workflow and check this node's output: you'll see multiple items, each with a new `fullName` and `age`."
      },
      "typeVersion": 1
    },
    {
      "id": "acd0b48a-ca88-4dae-ab19-b91db5050e8b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1300,
        60
      ],
      "parameters": {
        "color": 6,
        "width": 380,
        "height": 600,
        "content": "#### 🚀 ADVANCED LESSON 2: Using Helpers\n\nThis node also runs for each item, but demonstrates a powerful, advanced feature.\n\n**Goal:** Enrich data by calling an external API from code.\n\n**Key Concepts:**\n*   `this.helpers.httpRequest`: A built-in function to make API calls directly. This is great for dynamic URLs or when you need to add logic before or after the call.\n*   `await`: We use this because making an API call is an *asynchronous* operation.\n\n\nCheck the output: each user now has `gender` data fetched from the web!"
      },
      "typeVersion": 1
    },
    {
      "id": "da000098-d03f-40a9-b017-fab8223a6afc",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1700,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 380,
        "height": 580,
        "content": "#### ⚙️ LESSON 3: Processing All Items at Once\n\nThis node is in **\"Run Once for All Items\"** mode. It runs only once and sees all items at the same time.\n\n**Goal:** Aggregate data to create a summary.\n\n**Key Concepts:**\n*   `$items()`: Returns an **array** of all items from the previous node.\n*   `return [ { json: { ... } } ]`: Returns an array containing a single new item with the final result.\n\n\nCheck this node's output: there is only one item containing the total user count and their average age."
      },
      "typeVersion": 1
    },
    {
      "id": "5c84ce9f-32d0-4222-9b1a-3887677bdabe",
      "name": "6. Create a Binary File (Expert)",
      "type": "n8n-nodes-base.code",
      "position": [
        2240,
        480
      ],
      "parameters": {
        "jsCode": "// LESSON 4 (EXPERT): Creating a binary file.\n\n// This node runs only ONCE for ALL items.\n\n// 1. Get all items from the previous node\nconst allUsers = $(\"4. Fetch External Data (Advanced)\").all();\n\n// 2. Create a CSV string from the data\nlet csvContent = \"FullName,Age,GenderGuess,ProcessedBy\\n\"; // CSV Header\n\nfor (const item of allUsers) {\n  const user = item.json;\n  const row = `\"${user.fullName}\",${user.age},${user.gender},n8n`;\n  csvContent += row + \"\\n\";\n}\n\n// 3. Use a helper to create a binary file from the string\nconst binaryData = await this.helpers.prepareBinaryData(Buffer.from(csvContent), 'user_report.csv');\n\n// 4. Return a new item containing the binary data\nreturn [\n  {\n    json: {\n      reportGenerated: new Date().toISOString(),\n      userCount: allUsers.length\n    },\n    binary: {\n      'report': binaryData\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "498b1bf2-1ced-4343-b459-9b6226fa8c46",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2100,
        80
      ],
      "parameters": {
        "color": 3,
        "width": 380,
        "height": 580,
        "content": "#### 📄 EXPERT LESSON 4: Creating Files\n\n**Goal:** Aggregate all items and generate a binary file (like a CSV in that case).\n**Mode:** `Run Once for All Items`\n\n**Key Concepts:**\n*   `$(\"4. Fetch External Data (Advanced)\").all()`: Gets an array of ALL items from the 4th step.\n*   `this.helpers.prepareBinaryData`: Converts raw data (like a text string) into a proper binary file that n8n can use.\n*   `Buffer`: A standard way to handle binary data in JavaScript."
      },
      "typeVersion": 1
    },
    {
      "id": "c97edb6b-77ac-48ea-8e00-507770cc6373",
      "name": "Start Tutorial",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        220,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "877fc70d-8c0d-47c1-896c-da30260bc0df",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2500,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 540,
        "height": 800,
        "content": "## Was this helpful? Let me know!\n\nI really hope this tutorial helped you understand what you can do with the Code Node. Your feedback is incredibly valuable and helps me create better resources for the n8n community.\n\n### **Share Your Thoughts & Ideas**\n\nWhether you have a suggestion, found a typo, or just want to say thanks, I'd love to hear from you!\nHere's a simple n8n form built for this purpose:\n\n#### ➡️ **[Click here to give feedback](https://api.ia2s.app/form/templates/feedback?template=JS%20Code%20Node%20Tutorial)**\n\n### **Ready to Build Something Great?**\n\nIf you're looking to take your n8n skills or business automation to the next level, I can help.\n\n**🎓 n8n Coaching:** Want to become an n8n pro? I offer one-on-one coaching sessions to help you master workflows, tackle specific problems, and build with confidence.\n#### ➡️ **[Book a Coaching Session](https://api.ia2s.app/form/templates/coaching?template=JS%20Code%20Node%20Tutorial)**\n\n**💼 n8n Consulting:** Have a complex project, an integration challenge, or need a custom workflow built for your business? Let's work together to create a powerful automation solution.\n#### ➡️ **[Inquire About Consulting Services](https://api.ia2s.app/form/templates/consulting?template=JS%20Code%20Node%20Tutorial)**\n\n---\n\nHappy Automating!\nLucas Peyrin"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "1. Sample Data": {
      "main": [
        [
          {
            "node": "2. Split Out Users",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Tutorial": {
      "main": [
        [
          {
            "node": "1. Sample Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Split Out Users": {
      "main": [
        [
          {
            "node": "3. Process Each User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. Process Each User": {
      "main": [
        [
          {
            "node": "4. Fetch External Data (Advanced)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Calculate Average Age": {
      "main": [
        [
          {
            "node": "6. Create a Binary File (Expert)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. Fetch External Data (Advanced)": {
      "main": [
        [
          {
            "node": "5. Calculate Average Age",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Related Workflows

Automate Data Capture with Webhooks and HTTP Requests

Streamline your data collection process using webhooks to capture real-time data, set specific parameters, and send HTTP requests for automated processing. Ideal for AI-powered automation users. Requires 0 accounts. Save hours on manual data entry and effortlessly manage 100+ data points daily with this efficient workflow.

41,810 views
Miscellaneous

Sync Telegram Messages with OpenAI GPT for Instant Responses

Automate message handling using the Telegram Bot API and enrich responses with OpenAI GPT for intelligent conversations. This workflow is perfect for AI-powered automation users looking to streamline their communication. Requires 2 accounts: Telegram Bot Token and OpenAI API Key. Save hours on customer interactions and enhance user engagement with instant, AI-generated replies.

23,896 views
MiscellaneousAI Summarization

Automate User Logins with Auth0 Using n8n Workflow

Streamline user authentication by automating login processes with Auth0 via n8n. This workflow leverages HTTP requests, conditional logic, and error handling to create a seamless user experience. Perfect for developers and integrators. Requires 0 accounts. Save hours on manual login management and enhance security while providing instant access to users.

14,866 views
Miscellaneous

Extract & Clean Google News RSS URLs with n8n Automation

Seamlessly extract and decode URLs from Google News RSS feeds using n8n's RSS Feed Read, HTTP Request, and Code tools. Perfect for developers and integrators needing clean article links. Requires 0 accounts: simply set up your workflow and start processing. Save hours of manual URL cleaning and streamline your content curation process today!

10,523 views
Miscellaneous

How to Use This Workflow

1Import to n8n

  1. Copy the JSON using the button above
  2. Open your n8n instance
  3. Click “Import workflow” or press Ctrl+V
  4. Paste the JSON and click “Import”

2Before Running

Configure credentials and update service-specific settings before executing the workflow. Review required credentials in the Technical Details section above.

22.6K