Closed James-Quigley closed 4 years ago
Please use JSON.stringify
on each row and paste the result here. Chances are your editor is inserting a Byte Order Mark (BOM), in which case you should strip that character before sending data to csv-parser, but let's have a look at that JSON first.
I believe that is the case. I'm using VS Code. Is there a way to not save the BOM? Or do I just need to strip that leading character?
I'm not a VS Code user, so I'm afraid you'd have to ask those folks. But you can use intermediate tools like https://github.com/sindresorhus/strip-bom and https://github.com/sindresorhus/strip-bom-cli to do that as part of the process.
I found this issue as well. The CSVs were created using Excel. First saved as xlsx, then as CSV. Printing the JSON.stringify() showed the header as ' USER_NAME'
instead of the expected 'USER_NAME'
. I wasn't able to get around this by modifying the CSV file, but I could instead trim the headers using the included mapHeaders
function:
.pipe(csv({
mapHeaders: ({ header, index }) => header.trim()
}))
this is exactly what I needed, thank you! @fedpettinella
Expected Behavior
With a CSV looking like:
after parsing, accessing row.name should return a string
Actual Behavior
The row property doesn't actually have
name
, but rathername
preceeded by the utf char 65279, or a zero-width no-break space. I've created the CSV by hand, so I have no idea why that character would be in thereHow Do We Reproduce?