Closed NerdyLuffy closed 1 year ago
That is not how unwind works.
You probably want a custom unwind for you specific use case:
const { Parser } = require('@json2csv/plainjs');
const customUnwind = row =>
row.author.map((author, i) => ({
...(i === 0 ? { id: row.id, title: row.title } : {}),
author,
venue: row.venue[i],
addresses: row.addresses[i],
}));
const transforms = [customUnwind];
const json2csvParser = new Parser({ transforms });
const csvJudges = json2csvParser.parse(testData);
Hey @juanjoDiaz thanks for the response, how would go about when the array size of venue is greater than author in that case it will not append the records on the csv is there a way to handle different array sizes of Author and Venue ?
const customUnwind = row => {
const maxItems = [...Array(Math.max(row.author.length, row.venue.length, row.addresses.length)).keys()];
return maxItems(i => ({
...(i === 0 ? { id: row.id, title: row.title } : {}),
author: row.author[i] ,
venue: row.venue[i],
addresses: row.addresses[i],
}));
};
Expected Outcome is :