Last header field gets double-quoted (unexpected)
See original GitHub issueUsing 1.12.0 here, seeing a weird issue. If to project this problem on the sample:
var csv = require('csv-parser')
var fs = require('fs')
fs.createReadStream('some-csv-file.csv')
.pipe(csv())
.on('data', function (data) {
console.log('Name: %s Age: %s', data.NAME, data.AGE)
})
if AGE
is the last header field, it’s not possible to access it via data.AGE
, but it is possible to access it via data['"AGE"']
. What’s more interesting is that it happens only with the last header field. So, as a workaround it’s possible to add a comma at the end of the header field (which adds a new, zero-length header field). This gets data.AGE
(or data['AGE']
) to return the expected value.
Anyone else seen this issue?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
Unexpected quotes in header column name #237 - GitHub
9") to write Java Map Object to CSV files, I am seeing a weird thing. some of the header column generated are wrapped...
Read more >Python : csv unexpected quotes in last element - Stack Overflow
I'm using Python 2.7.6 and learning to use the csv module. My script somehow added unexpected double quotes and several spaces after my...
Read more >Problem querying a CSV File with Synapse SQL Serverless Pool
Hello,. trying to query a very simple CSV file, Strings have Double quote ("). SELECT TOP 100 * FROM OPENROWSET(
Read more >Transform failed to process result using 'successTemplate'
... result using 'successTemplate' template due to error:'Unexpected character ('\' (code 92)): was expecting double-quote to start field ...
Read more >Solved: How to remove double quote from csv file
I m loading csv file into Hive orc table using data frame temporary table. After loading into Hive table data is present with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a similar issue with the first header field. The object returned ended up looking like this:
Row { ' ID': '', PHOTOS: '28', TOWN: '', MAP: '', AKA: '', SUBURB: '', ADDRESS: '', HERITAGE: '', NAME: '', DENOMINATION: '', CHECKED: '', CORRECTED: '', NOTES: '', LOCATION: '' }
The issue was the original source CSV from excel was saved with a Byte order Mark which added a character at the start of the file. I suspect your source file may have a non recognized line break character at the end of your header line (or may have Carriage Return and Line Break)
It may be worth opening it in notepad and re-saving it or trying setting the raw: false constructor option or trying newLine: ‘\r\n’
Or just download TextEdit and open the file then re-save it using another encoding (which is what I ended up doing)
I had the same issue with Byte order Mark. On a Mac, you can clean up your CSV files using this command in a terminal:
sed $'s/\xEF\xBB\xBF//g' file.csv