When using node-csv-parse, can you specify some fields to be text-qualified and some not?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



When using node-csv-parse, can you specify some fields to be text-qualified and some not?



Using SSDT, I can specify whether individual fields are text-qualified or not. This is useful for a CSV that I'm parsing where only one of the fields is text qualified (I can't easily ask for an export where all the fields are text qualified).



Using the CSV parsing library adaltas/node-csv-parse, I see that you can specify a text qualifier (i.e. the quote param) but that this seems to be for either all fields or no fields.


quote



Is it possible to specify that certain fields are text-qualified (i.e. "qualified" and certain fields NOT to be text-qualified (i.e. not qualified)? Then, since this seems a good place to ask it, is it possible to specify different qualifiers for different fields when parsing a CSV?


"qualified"


not qualified



I don't think that the CSV specification has anything to say on this, but shouldn't either all fields or no fields be text-qualified??




1 Answer
1



In csv, quotes are used around fields that contain a separator (or another quote or newline in multiline fields):


123,"some, text",456



Escaping quotes:


123,"24"" monitor, Samsung",456



Multiline field:


123,"some text on
multiple lines",456



That is actually the only purpose of quotes in csv (except some special cases for Excel).



They don't have to be used on the other data:


123,"some, text",456
234,some text,567



Using quotes doesn't mean the fields should be treated as text vs number. That's up to the application:


123,"some, text","456,2"
"234,41",some text,"5,67"



So in general a csv writer should only place quotes where needed (all other quotes only take extra space and parsing time).





Thanks - so it's best practice to only use quotes strictly where required?
– Zach Smith
Aug 6 at 14:45





@ZachSmith Yes, as far as the writer supports that. Usually the setting is something like quote=auto.
– Danny_ds
Aug 6 at 14:55


quote=auto





Ah thanks - that's probably why i am parsing a CSV like this
– Zach Smith
Aug 6 at 20:58





Question. Are qualifier chars only considered qualifiers by parsers if these chars appear as next to a column delimiter?
– Zach Smith
Aug 21 at 11:48






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS