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.

Problem with escaped quotes

See original GitHub issue

I have got a csv file that is straightly exported from MySQL and I want to read and parse in Node.js. But I get errors whenever it reaches something that has escaped quotes on it. For example, “Foo "Bar"”, “Baz”, “”, “”

This will give error

      throw er; // Unhandled 'error' event
Error: Parse Error: expected: '"' got: 'B'. at 'Bar" Foo",
at parseEscapedItem(node_modules/fast-csv/lib/parser/parser.js:79:19)

As a workaround, I ended up doing something like this, Reading it line by line and convert \" to "" instead. But it seems not possible to do it using other methods than fromString().

var csv = require("fast-csv");
var byline = require('byline');

var stream = byline(fs.createReadStream("mydata.csv", { encoding: 'utf8' }));
stream.on('data', function(line) {
  line = line.replace(/\\\"/g, '""');

    .on("data", function (data) {
      // data 
    .on("end", function () {


Would that be potentially a bug?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

dustinsmith1024commented, Jul 27, 2015

My fault I think you want quote: '\\' instead of escape.

var csv = require("fast-csv");

var line = '"Foo \"Bar\"", "Baz", "", ""';
  csv.fromString(line, { quote:'\\'})
    .on("data", function (data) {
    .on("end", function () {

➜  c2fo git:(master) ✗ node test.js
[ '"Foo "Bar""', ' "Baz"', ' ""', ' ""' ]
doug-martincommented, Jul 29, 2019

I dont think the solution above is doing what people think it is. It is setting the quote to a \ character basically ignoring quoting in the examples.

@Jeerjmin can you provide a small example so I can try to reproduce and fix the underlying issue. Also what version of the package are you using?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escape Quotes - BrainyQuote
You will find peace not by trying to escape your problems, but by confronting them courageously. You will find peace not in denial,...
Read more >
Problem with escaped quotes in variable (I think) [duplicate]
Closed 9 months ago. I am trying to write a parameter driven routine to extract parts of audio files using ffmpeg. Because the...
Read more >
Problems (with escaped quotes?) in Turtle input #165 - GitHub
Hi HDTers, the following Turtle (an output of easyrdf's Turtle serializer [1]) is not swallowed by HDT (more concretely by rdf2hdt).
Read more >
problem escaping quotes in script - Unix Stack Exchange
I've tried escaping the single quotes with backslash within the construction loop, double-escaping with double-quoted single quotes, swapping ...
Read more >
CSV Reader / Writer: Escaped quotes causing problems
In particular, there are two issues which are: If a quote is already present in the data, it is either replaced (i.e. by...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found