One json item instead of multiple items

I’m trying to get this json response to be split in single items with the SplitinBatches node. But all items are somehow one item instead of 4 single items. How would I get this working?

{
  "nodes": [
{
  "parameters": {
    "functionCode": "return [\n{\n\t\"json\": [{\n\t\t\"24\": {\n\t\t\t\"quantity\": 1,\n\t\t\t\"sku\": \"SKU1\",\n\t\t\t\"lastModified\": \"2020-10-30T00:28:14+00:00\"\n\t\t},\n\t\t\"25\": {\n\t\t\t\"quantity\": 10,\n\t\t\t\"sku\": \"SKU2\",\n\t\t\t\"lastModified\": \"2020-10-30T00:28:17+00:00\"\n\t\t},\n \t\"28\": {\n\t\t\t\"quantity\": 8,\n\t\t\t\"sku\": \"SKU24\",\n\t\t\t\"lastModified\": \"2020-10-30T00:28:17+00:00\"\n\t\t},\n \t\"29\": {\n\t\t\t\"quantity\": 4,\n\t\t\t\"sku\": \"SKU13\",\n\t\t\t\"lastModified\": \"2020-10-31T00:24:17+00:00\"\n\t\t}\n\t}]\n}\n];"
  },
  "name": "Function1",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    530,
    300
  ]
},
{
  "parameters": {
    "batchSize": 1,
    "options": {}
  },
  "name": "SplitInBatches1",
  "type": "n8n-nodes-base.splitInBatches",
  "typeVersion": 1,
  "position": [
    760,
    300
  ]
}
  ],
  "connections": {
"Function1": {
  "main": [
    [
      {
        "node": "SplitInBatches1",
        "type": "main",
        "index": 0
      }
    ]
  ]
}
  }
}

Hey @paul123!

Your data has a single object within the array. The Spilt In Batches node considers this as one single batch and returns it. I have modified your workflow and made some changes to it. The Create array Function node, converts the object into an array. The Create JSON-items Function node, creates individual JSON items for the objects within the array. The Split In Batches node will now split the data into batches.

Hope this helps!

1 Like

Many thanks @harshil1712 that works perfect! :facepunch:

1 Like

I am glad it worked! Have fun! :slightly_smiling_face: