How to manage nested arrays of objects in Zapier without reverting to separate arrays?

Hello everyone, I'm encountering a challenge with my JavaScript code in Zapier. I'm trying to process data obtained from Airtable, which arrives as three separate arrays:

```javascript
categoryList[]
itemList[]
descriptionList[]

I loop through these arrays, breaking them apart at the commas, and then organize each value into an individual object that I add to a new array. My ultimate objective is to create a JSON payload for PDFMonkey that looks like this:

{
    "data": [
        {
            "itemName": "sample item",
            "itemCategory": "sample category",
            "itemDescription": "sample description"
        },
        ...
    ]
}

While Zapier returns the correct format, I find that when I try to access the data in following steps, it reverts to separate arrays. The output from my Zapier code appears as:

itemList
1
itemCategory
Kitchen Appliances
itemName
Gas Stove
itemDescription
Brand Model Gas Stove
...

However, during later processing, I receive it as individual arrays like:

itemArrayItemName: itemName[1],itemName[2],...
itemArrayItemCategory: itemCategory[1],itemCategory[2],...
itemArrayItemDescription: itemDescription[1],itemDescription[2],...

Below is the code I am currently using for reference:

// async function

const categories = inputData.categoryList.split(/\s*,\s*/);
const items = inputData.itemList.split(/\s*,\s*/);
const descriptions = inputData.descriptionList.split(/\s*,\s*/);

let constructedArray = [];

for (let index = 0; index < categories.length; index++) {
    const entry = {
        itemCategory: categories[index],
        itemName: items[index],
        itemDescription: descriptions[index]
    };
    constructedArray.push(entry);
}
output = { data: constructedArray };

Is there a method to “flatten” or convert the JSON object so it maintains the desired structure for subsequent Zapier steps? Thank you for your assistance!

hey CreativePainter33, you could try using code by zapier to run a node step. Inside it, you can transform your nested arrays into objects directly within zapier. This approach might keep your data in the structure you want. Sometimes zapier needs a little tinker to behave!

You might want to consider using a single group operation in the Zapier “Formatter” to concentrate the data into a singular JSON object. Ensuring each of your arrays is consistently ordered is crucial as it helps maintain the alignment of data throughout the process. Pre-process your data before sending to Zapier, enriching it with logic that doesn’t break apart the structure. You have the option to concatenate arrays into a cohesive JSON structure in Code by Zapier or perhaps store and retrieve using a key-value store like Redis, maintaining relationships at every step.