Advanced parser csvutils.parseWithOptions()

Use this parsing function when handling different formats such as TSV, files without headers, or specific parsing rules.

Syntax:

var result = csvutils.parseWithOptions(data, options); // data is a string, options is an object

The options parameter is a JavaScript object used to configure the parser, with all optional properties.

This table shows the properties you can use for this function:

Type Property Description Default value
String format

The file format.

These are the options you can specify:
  • Default: Standard CSV.
  • Excel: CSV exported from Microsoft Excel.
  • TDF: Tab-separated values
Default
Char delimiter The character used to separate fields. ,
Char quote The character used to enclose fields that contain special characters. "
Boolean header

Determines how the first row of the returned data is handled.

These are the options you can specify:
  • true: Uses the first row as column names and returns an array of maps.
  • false: Uses the first row as data and returns an array of arrays.
false
Array headers The list of custom header names to use if the file does not contain a header row. none

Return data structures for header options

The structure of the returned data depends on how you configure the header options.

This table shows the scenarios when configuring headers in the function:

Scenario Description Use case
Headers enabled If you set the header to true or provide a list of headers, an array of maps is returned by the system. You must access data by column name. For example, row["Email"].
Headers disabled If you set the header to false and no manual headers are provided, an array of arrays is returned by the system. The file to use has no headers, or you prefer accessing data by index. For example, row[0].