node-csvtojson
node-csvtojson copied to clipboard
CSV file has duplicate headers but json doesn't have duplicate column. Is there any option to change this behavior.
Hi, can you give an example?
~Keyang
@Keyang Example: csv file has header: firstName, lastName, firstName values: [ abc,test,xyz]
Json result:
{ lastName: 'test', firstName: 'xyz' }
This creates problem for me because I wouldn't know if file had duplicate columns.
I am handling this using 'header" event like this:
let duplicateDetected=false; stream.pipe( csv({delimiter:'auto'}).on('error', (err) => { //handle error }).on('header',(header)=>{ //check for duplicate duplicateDetected=true; } }) ).then((jsonData) => { if(!duplicateDetected){ //continue logic } });
I am assuming then function will be called at the end not before setting 'header' event. Is this assumption correct?
Any news on this issue? I have the same problem. Duplicated headers as my source CSV transform multiple values in duplicated headers.
Thanks !
I have the same issue and would like to have this fixed. Also what about blank headers?
@Keyang has replied about how to handle such scenario in this issue: https://github.com/Keyang/node-csvtojson/issues/217 The idea is to gather the duplicate headers by tapping into the "header" event and then using that to change the headers that get used as JSON keys using the "csv" approach.
@Keyang , I would like to contribute to this bug fix by adding a change to rename the Duplicate Headers with their count appended to it. I have a fix ready locally but would like to have your feedback on the approach before proceeding with a Pull request.