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.

First row's header quoted

See original GitHub issue
  • Operating System: Docker node:8-slim
  • Node Version: 8.16
  • NPM Version: 6.4.1
  • csv-parser Version: 2.3.0

Expected Behavior

Data of

col1,col2,col3
a,2,foobar

becomes:

[
	Row {
		col1: 'a',
		col2: '2',
		col3: 'foobar'
	}
]

Actual Behavior

[
	Row {
		'col1': 'a',
		col2: '2',
		col3: 'foobar'
	}
]

Notice how the first column’s header has a single quote around it: 'col1'.

How Do We Reproduce?

File was created from Excel (using 16.24 via Office 365 subs). File has been checked with text editor and confirmed does not have a quote around the first column’s header.

test-csv-parser.csv.zip

Code

const csv = require('csv-parser')
const fs = require('fs')
const results = [];

fs.createReadStream('test-csv-parser.csv')
  .pipe(csv())
  .on('data', (data) => results.push(data))
  .on('end', () => {
    console.log(results);
  });

This may be related with #127 .

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

3reactions
nickpaintercommented, Nov 12, 2019

@daytonmills I discovered that this issue can be reproduced by simply setting the encoding to UTF-8-BOM within notepad++. This is also the format that excel uses when saving csv files by default. A workaround is to manually change the encoding to UTF-8.

For future people stumbling on my comment. https://github.com/mafintosh/csv-parser#byte-order-marks documents the issue well and contains a solution.

2reactions
nickpaintercommented, Oct 30, 2019

@daytonmills I discovered that this issue can be reproduced by simply setting the encoding to UTF-8-BOM within notepad++. This is also the format that excel uses when saving csv files by default. A workaround is to manually change the encoding to UTF-8.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write quotes round all fields except first (heading) row
QuoteNoFields = true; cw.WriteHeader<YourClassNameHere>(); cw.NextRecord(); // without this first row is on same line as header cw.Configuration ...
Read more >
quotes around column headings in CSV file
When I save my CSV file, quotes are put around all text values, even the column headings / field names. Then when I...
Read more >
Quote Line Editor column headings - IdeaExchange - Salesforce
The column headings in the Quote Line Editor disappear as you scroll down. It would be extremely useful and productive to have these...
Read more >
Column names in header row have quotes - MSDN - Microsoft
I figured out how to get the string/text data surrounded by double-quotes, but the setting also quotes the column names in the header...
Read more >
how to eliminate double quotes for column headers in ...
I don't think it should double quote the header part. yes it is exactly double quotes (because when i clear the Columns name...
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