Can't get SplitInBatches to work with Function node

I have a function Node, and by using the following code:

const PrintfulPayload = {
 
vars: items[0].json.vars
  
};

PrintfulPayload 

return [
  {
    json: PrintfulPayload 
  }
];

I am able to get:

[
   {
      "vars":[
         {
            "id":6834,
            "product_id":5,
           
         },
         {
            "id":6835,
            "product_id":5,
         }
      ]
   }
]

But the SplitInBatches seems to need the data without the array like:

[
   {
         {
            "id":6834,
            "product_id":5,
           
         },
         {
            "id":6835,
            "product_id":5,
            
         }
   }
]

If I try and get it without, like:

const PrintfulPayload = {
 
 
 items[0].json.vars
  
};

PrintfulPayload 

return [
  {
    json: PrintfulPayload 
  }
]; 

It throws an error. How do I get just a list of the array items?

Hey @gravitoad!

The output from the Function node is returning an object which contains the array. The SplitInBatches node takes this as a single input and returns the whole object as the output. Instead of returning a single object, you want to return multiple objects. Similar to the following example

[
         {
            "id":6834,
            "product_id":5,
           
         },
         {
            "id":6835,
            "product_id":5,
         }
]

Below is an example that might help. The first two function nodes are creating the mock data. You want to use the Create JSON-items function node.

Hope this helps! :slightly_smiling_face:

That did the trick, thanks a bunch!

I am happy that this worked! Have fun! :slightly_smiling_face: