Problem with escaped quotes
See original GitHub issueI 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
events.js:141
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, '""');
csv.fromString(line)
.on("data", function (data) {
// data
})
.on("end", function () {
});
});
Would that be potentially a bug?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
My fault I think you want
quote: '\\'
instead of escape.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?