Closed tetsu9923 closed 1 year ago
May I ask how it was done ?
@tetsu9923 were you able to reach a solution? I'm running into the same issue recently.
CSV is a format that requires a static number of columns. For that reason it doesn't make sense to have an array of unknown length. You might end up with tons of columns and with lots of blanks.
If you really want to do this, the only way is to preprocess the data to extract the list of possible headers and filter the ones that you want.
Thank you for providing great JSON to CSV converter. We are getting trouble with specifying columns that are flattened by
transforms: [flatten({ arrays: true })]
. Details are shown below.Filing an issue
Include the version of json2csv used. 7.0.1
Include your node version/browser vendor and version. 18.9.1
Include the command or code you used.
const data = [ { car: "Audi", price: 40000, color: ["black", "blue"], # The length of the array is unknown until it is processed. }, { car: "BMW", price: 35000, color: ["red", "blue"], # The length of the array is unknown until it is processed. }, ]
const fields: Array = ["car", "color"]
const parser = new Parser({ fields: fields, transforms: [flatten({ arrays: true })] }) const csv = parser.parse(data) console.log(csv)
Current result:
The length of the array is unknown until it is processed, so we cannot set fields argument like
["car", "color.0", "color.1"]
. We are looking for the solution. Thank you.