csvnode-csv-parse

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.

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?

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??


Solution

  • 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).