question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Last header field gets double-quoted (unexpected)

See original GitHub issue

Using 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:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
Dastaricommented, Aug 21, 2018

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)

1reaction
jdevostcommented, Oct 4, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found