Skip to content
Advertisement

First property inaccsesible of objects parsed by csv-parse

I am parsing a csv file with following contents using csv-parse

JavaScript

However, on the objects returned it isn’t possible to access the property created from the first column userID.

Here is my code —

JavaScript

Output –

JavaScript

I notice the first column key userID has single quotes around it in the console output where as sysID doesn’t. But don’t know what is causing them.

Advertisement

Answer

Figured it out myself in the end…

I needed the BOM option. The documentation states it should be set to true for UTF-8 files. But it defaults to false.

Excel by default generates csv files with BOM as the first character in CSV files. This gets picked up as part of the header (and key name) by the parser. With the bom option set to true, it can handle csv files generated from excel or other programs.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement