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

Resultant JSON in lowercase if csv file has only two rows and convert header to lowercase

Open adlorenzo30 opened this issue 5 years ago • 2 comments

If I have a csv file with two rows like this: Name,AGE John,23

When use: csvToJson({trim:true}) .fromFile(filePath) .preFileLine((fileLine,idx)=>{ //Convert csv header row to lowercase before parse csv file to json if (idx === 0 ){return fileLine.toLowerCase()} return fileLine; })
.then(jsonObj => { console.log(jsonObj) } print [{name:john,age:23}] everything in lowercase, but what I want is only the keys in lower case, not the values in the resultant JSON. This only apend when the file has two rows (header row and another). If the file have three or more rows like this: name,age John,23 Amelia,20
The result is correct [{name:John,age:23},{name:Amelia,age:20}]

adlorenzo30 avatar Feb 07 '20 23:02 adlorenzo30

Duplicate of #351 Both seem to occur because the counter isn't incremented correctly for the last line

DubKF avatar Apr 10 '20 11:04 DubKF

Bump!

prateekkathal avatar Oct 21 '20 06:10 prateekkathal