How to loop using Split In Batches Node with array data

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
          }
        ]
      ]
    }
  }
}

Hey @sinagawa!

Welcome to the community :sparkling_heart:

The code snippet mentioned here might be helpful in converting the data so that n8n understands it and processes it. JavaScript Code Snippets | Docs

Hi @harshil1712 :grinning:

Thank you for your help. :grinning:

{
  "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
          }
        ]
      ]
    }
  }
}

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
          }
        ]
      ]
    }
  }
}

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

Thank you for your reply.