# How to loop using Split In Batches Node with array data

**URL:** <https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469>\
**Category:** Questions\
**Tags:** core\
**Created:** [June 25, 2021, 11:17am UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469 "2021-06-25T11:17:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinagawa](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/sinagawa/32/5358_2.png) [@sinagawa](https://community.n8n.io/u/sinagawa)\
**Post date:** [June 25, 2021, 11:17am UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469/1 "2021-06-25T11:17:31Z")

</div>

Hello. I am a newbie of n8n.  
First off, thanks for the great tool, I am enjoying working with it!

Each n8n node runs its operations on each item in the array.  
In normal cases, in the first data structure it attempts operates N times on {json:obj}.  
The first data structure attempts to operate N times on {json:obj}.  
But it operates just once on the json array object.  
[Object: {“jsonData”:[…]}}]

Please, how to solve it?

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        200,
        300
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"HTTP Request\"].json[\"country_code\"]}}",
              "value2": "US"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1000,
        100
      ]
    },
    {
      "parameters": {
        "command": "=echo '\"success {{$node[\"SplitInBatches\"].json}}\"' >> ./http_access.log"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1200,
        100
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1300,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "// ipData = $node[\"recivedNode\"].json[\"data\"];\nlet ipData = [\"8.8.8.4\", \"8.8.8.8\", \"8.8.8.9\", \"192.168.10.10\"];\n\njsonStr = JSON.stringify(ipData);\njsonData = JSON.parse(jsonStr);\n\nreturn [{json:{jsonData}}];\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        350,
        300
      ]
    },
    {
      "parameters": {
        "url": "=http://api.ipstack.com/{{$node[\"SplitInBatches\"].json}}?access_key=0a81636c6f70330b8f68ccc6819daa46",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        800,
        100
      ]
    },
    {
      "parameters": {
        "functionCode": "return items;"
      },
      "name": "Transform to table",
      "type": "n8n-nodes-base.function",
      "position": [
        500,
        390
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [June 25, 2021, 3:28pm UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469/2 "2021-06-25T15:28:40Z")

</div>

Hey @sinagawa!

Welcome to the community 💖

The code snippet mentioned here might be helpful in converting the data so that n8n understands it and processes it. [JavaScript Code Snippets | Docs](https://docs.n8n.io/reference/javascript-code-snippets.html#_1-create-multiple-items-from-a-single-item)

---

<div class="post-metadata">

**Author:** ![sinagawa](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/sinagawa/32/5358_2.png) [@sinagawa](https://community.n8n.io/u/sinagawa)\
**Post date:** [June 26, 2021, 12:23am UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469/3 "2021-06-26T00:23:07Z")

</div>

Hi @harshil1712 😀

Thank you for your help. 😀

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        150,
        300
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"country_code\"]}}",
              "value2": "US"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1000,
        100
      ]
    },
    {
      "parameters": {
        "command": "=echo '\"success form {{$json[\"ip\"]}}\"' >> ./http_access.log"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1200,
        100
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1300,
        290
      ]
    },
    {
      "parameters": {
        "url": "=http://api.ipstack.com/{{$json[\"item\"]}}?access_key=0a81636c6f70330b8f68ccc6819daa46",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        800,
        100
      ]
    },
    {
      "parameters": {
        "functionCode": "let ipData = [\"8.8.8.4\", \"8.8.8.8\", \"8.8.8.9\", \"192.168.10.10\"];\n\nreturn [{json:{ipData}}];\n"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.ipData.map(item => {\n return {\n json: {item}\n }\n});\n"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function2": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [June 26, 2021, 12:29am UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469/4 "2021-06-26T00:29:02Z")

</div>

Check the example below. Those split batches nodes do not think are needed. Also, next time you share a workflow make sure you do not filter your access token, if it was in the credentials that would not be an issue but since it’s in the URL when you copy the workflow that is also copied.

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"HTTP Request\"].json[\"country_code\"]}}",
              "value2": "US"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1160,
        300
      ]
    },
    {
      "parameters": {
        "command": "=echo '\"success {{$node[\"SplitInBatches\"].json}}\"' >> ./http_access.log"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1360,
        300
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1460,
        490
      ]
    },
    {
      "parameters": {
        "functionCode": "// ipData = $node[\"recivedNode\"].json[\"data\"];\nlet ipData = [\"8.8.8.4\", \"8.8.8.8\", \"8.8.8.9\", \"192.168.10.10\"];\n\nconsole.log(ipData.map((ip) => ({ json: ip })))\n\nreturn ipData.map((ip) => ({ json: { ip } }))\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {
        "url": "=http://api.ipstack.com/{{$node[\"Function\"].json[\"ip\"]}}?access_key=0a81636c6f70330b8f68ccc6819daa46",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![sinagawa](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/sinagawa/32/5358_2.png) [@sinagawa](https://community.n8n.io/u/sinagawa)\
**Post date:** [June 26, 2021, 1:13am UTC](https://community.n8n.io/t/how-to-loop-using-split-in-batches-node-with-array-data/6469/5 "2021-06-26T01:13:37Z")

</div>

@RicardoE105 Your workflow works simply and quickly. 😀 😀 😀  
If you don’t use these split batches, the log results store will only success the first conditions. 😂  
I will find a way to save all the results to meet all conditions. 👨‍🔧  
And I’ll change the access token.

Thank you for your reply.
