node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

ignoreColumns is not working

Open onsightit opened this issue 3 years ago • 1 comments

I occasionally get CSVs that have an extra comma on the header and rows. This results in the parser giving me unwanted columns, like 'field18'. I tried using the ignoreColumns option parameter like this:

		const converter = csv({
			noheader: false,
			ignoreColumns: /field\d+$/
		})

Or even hardcoding the column like this:

		const converter = csv({
			noheader: false,
			ignoreColumns: /field18/
		})

But it still gives me these unwanted columns. I suspect it is because 'field18' is not in the header. How can I get around this without deleting the trailing commas? I have an automated process, so manually editing the CSV is not an option.

Thanks!

onsightit avatar Oct 27 '22 21:10 onsightit

I found the option to skip empty data columns, you can use ignoreEmpty.

const converter = csv({ noheader: false, ignoreEmpty: true })

Kyaw-Zin-Thant avatar Dec 22 '22 17:12 Kyaw-Zin-Thant