Skip to content
Advertisement

csv-parse is throwing Invalid Opening Quote: a quote is found inside a field at line

I know there are other posts out there but none of them seem to fix my issues. I am using csv-parse with node js. This is the CSV header and record that I’m trying to parse.

JavaScript

I have no control over this file. I just need to be able to parse it. You will see that there is a double quote at the end of the description: TFal B2080264 INI TNS GRY SAUTE PN 8".

I need the double quote to stay there and for that to parse as one field. I keep getting this error:

Invalid Opening Quote: a quote is found inside a field at line 2.

The quote is not an opening. It’s technically a closing. But regardless, it will not parse.

This is currently my code:

JavaScript

I have removed some of the params and tried others, to no avail. Any ideas??

Advertisement

Answer

This code works fine with the latest csv-parse version (5.0.4). Which version of the csv-parse package are you using? I ask because it looks like the option may have been renamed from relax to relax_quotes only recently.

So, I think the solution is either:

  1. upgrade to the latest csv-parse, and indicate relax_quotes, or
  2. stay with your current version of csv-parse, and indicate relax

Just to be sure relax_quotes works with the current library, I tested the following code and it worked as expected:

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement