Skip to main content

CSV Formatter component

Formats the input array into a CSV string. This operation is the reverse of CSV Parser.

component image

In-ports

input Array — input array. Its elements can be either arrays or objects representing rows.

columns Array — an array of headers to include in the resulting CSV string.

Out-ports

output String — emits the resulting CSV string.

Overview

This component converts an array of rows or array of objects into a CSV string. It also supports TSV (tab-separated values) format and let you specify a custom delimiter symbol.

To format an array, pass it to the input port. Its elements can be either arrays or objects representing rows. First element may be used to read column headers. Alternatively, column headers can be passed in a separate array to the columns in-port.

The output port will emit the resulting CSV string where array’s elements are converted to rows separated by a newline (\n), and elements of these rows are separated with a delimiter. Values that contain either commas, double-quotes (") or newline (\n) are escaped using double-quotes.

Data examples

An example of input as array of objects:

[
{ "Year": "1997", "Make": "Ford", "Model": "E350", "Length": "2.34" },
{ "Year": "2000", "Make": "Mercury", "Model": "Cougar", "Length": "2.38" }
]

The same data can be passed to input as an array of arrays:

[
["Year", "Make", "Model", "Length"],
["1997", "Ford", "E350", "2.34"],
["2000", "Mercury", "Cougar", "2.38"]
]

Both of the inputs above will produce the following CSV string:

Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38

Settings

Output format

Specifies the output string format:

  • CSV (Comma-separated values)
  • TSV (Tab-separated values)
  • Custom delimiter

Delimiter

Specifies the delimiter symbol used to separate row elements. For example, a semicolon (;) or vertical bar (|).

Headings in the first row

Specifies whether headers are read from the first element of the input array or passed to the columns in-port. The resulting CSV string will include only those columns for which headers are passed to the columns port. The order of the columns corresponds to the order of the headers.

CSV Parser