Search code examples
javascriptzapier

Creating Multiple CSV from array in Zapier


[{'Product': '8 "', 'Quantity': '2', 'Flavour': 'B Choc'},
 {'Product': '10"', 'Quantity': '1', 'Flavour': 'Lemon'},
 {'Product': '10"', 'Quantity': '1', 'Flavour': 'Vanilla'},
 {'Product': '12"', 'Quantity': '2', 'Flavour': 'Carrot'}]

The number of sets of data is variable, this one happens to have 4 sets. Each set of data array will always contain "Product", "Quantity", and "Flavour".

What I need is this:

Product: 8",10",10",12"
Quantity: 2,1,1,2
Flavour: B Choc,Lemon,Vanilla,Carrot

I have been able to get a CSV for each row, but not a CSV for each column.

this code:


const lines = JSON.parse(inputData.lines);
const csv = await toCSV(lines);

output = [{csv}];

Produced this: csv:

Product,Quantity,Flavour
"8 """,2,B Choc
"10""",1,Lemon
"10""",1,Vanilla
"12""",2,Carrot

Solution

  • thanks for everyones help (;-)

    Once I removed the second line of code

    const csv = await toCSV(lines);

    I was amazed to see that the first const command had created exactly what I needed. I could use the data in either lines or CSV format. I got lines format.