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.
parseCSV(string, json)
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 is false
. If true
, 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).
[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
.
firstLineIsHeader=false
Example:
Or explicitly set firstLineIsHeader
to false
:
Result:
firstLineIsHeader=true
Example:
Result:
Note: If no separator
is specified, parseCSV
will auto-detect a common delimiter like commas or tabs based on the input structure.
Example:
Result:
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:
textQuote
characterYou can set a textQuote
character, such as a single quote ('
), to handle fields with quoted text specifically.
Example:
Result: