parseCSV
To return a structured list or array of rows and data from specified CSV text
The parseCSV
function parses CSV-formatted text into a structured list or array. You can customize parsing behavior by setting headers, separators, and text quote characters.
Syntax
parseCSV(string, json)
Parameters
data (string): The CSV text input. Example:
"Name,Age\nKiran,42\nLisa,27"
options (JSON object): Optional configuration, with the following properties:
firstLineIsHeader:
boolean
, default isfalse
. Iftrue
, the first line is treated as column headers.separator:
string
. Sets the delimiter between fields, such as","
or";"
. Auto-detects if not specified.textQuote:
string
. Specifies the character used to quote text fields. Default is"
(double quotes).
Return
JSON: A list or an array of JSON objects, with keys from the header if firstLineIsHeader
is true
.
[text]: A list or an array of text arrays (rows), if firstLineIsHeader
is false
.
Examples
1. Default firstLineIsHeader=false
firstLineIsHeader=false
Example:
Or explicitly set firstLineIsHeader
to false
:
Result:
2. Using firstLineIsHeader=true
firstLineIsHeader=true
Example:
Result:
3. Custom separator
Note: If no separator
is specified, parseCSV
will auto-detect a common delimiter like commas or tabs based on the input structure.
Example:
Result:
4. Specifying textQuote
textQuote
Note: Use textQuote
to specify a character for quoting fields. It's optional to quote every field; parseCSV
will still correctly read unquoted fields.
In this example, text fields are quoted with single quotes.
Example:
Result:
5. Using custom textQuote
character
textQuote
characterYou can set a textQuote
character, such as a single quote ('
), to handle fields with quoted text specifically.
Example:
Result:
Last updated