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!