node-csv
node-csv copied to clipboard
Escape comma inside a column
Hi,
My raw data got a comma from a certain field, While I'm parsing the data it cause me to have a new column instead. How do you escape a comma inside a column to prevent this?
Here is a example of raw csv data
"[email protected], [email protected]",email.org,none,bad
now the data returned from me is
[[email protected],[email protected],email.org,none,bad]
What I'm expecting is
["[email protected],[email protected]",email.org,none,bad]
I tried to escape the comma by escape: '\\,' but it doesn't help
My understanding is: "[email protected], [email protected]",email.org,none,bad is the source and you expect ["[email protected],[email protected]",email.org,none,bad], right ?
This seems like the default behavior to me. I checked and can confirm with our online tool
Yes that is correct, is this a default config?
Hi,
I am escaping the double quotes and I need to escape that because some of the fields do have double quotes inside the field for example:

So this is my config btw:

Hi, I'm using the default config.
Now the error is:
Invalid Closing Quote: got "d" at line 1 instead of delimiter, record delimiter, trimable character (if activated) or comment
Because I have this double quote inside a field:

The screenshot I shared use the default config.
Please share a minimalist and complete example for additionnal help.
Hi,
I was using the default config, I'm okay with the first issue which has the comma inside, now I have double quotes inside the field and it says

Here is the input please focus on the 2nd line which has the double quotes inside the field

Honestly, I don't think there is much we can do to handle such a scenario. The first quote place the parser in quoting mode and second quote is not escape which makes the field invalid
I can actually escape the comma, using the option escape. Can I escape multiple characters?
I've tried escape: ',"' but I didn't work
Yes, escape may be composed of multiple characters: https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/test/option.escape.coffee#L69-L79
how?
Look at the tests with the link above, I based my answer on them.
it didn't work, I think the link above you've provided will work if the character is contiguous.
Mine have to escape comma and double quotes just like this escape: ',"' unfortunately this doesn't work also as well