Skip to main content

csv-parser

Parse CSV strings into arrays/objects or stringify arrays into CSV format.

Overview

The csv-parser node converts between CSV text and JavaScript arrays/objects. Parse CSV files and data streams into structured objects using header rows, or stringify arrays back to CSV format. Supports configurable delimiters, header row detection, and row skipping.

Parse
CSV to objects
Stringify
Objects to CSV
Headers
Auto-detect
Custom
Delimiter

Properties

Property Type Default Description
action string "parse" "parse" (CSV → objects/arrays) or "stringify" (arrays → CSV)
delimiter string "," Field delimiter character (comma, tab, semicolon, pipe, etc.)
hasHeader boolean true First row contains column headers (used as object keys)
skipRows number 0 Number of rows to skip from the beginning before processing

Parse Output Modes

With Headers (hasHeader: true)

Each row becomes an object with header names as keys

Input:  "name,temp,humidity\nA,23.5,65"
Output: [{ name:"A", temp:"23.5", humidity:"65" }]

Without Headers (hasHeader: false)

Each row becomes an array of values

Input:  "A,23.5,65\nB,24.1,62"
Output: [["A","23.5","65"],["B","24.1","62"]]

Example: Parse Sensor Data Log

Parse a CSV file containing sensor readings into structured objects.

// csv-parser node configuration
{
  "action": "parse",
  "delimiter": ",",
  "hasHeader": true,
  "skipRows": 0
}

// Input CSV in msg.payload.data:
// "timestamp,sensor,temperature,humidity
// 2024-01-15T10:00:00,DHT22,23.5,65
// 2024-01-15T10:05:00,DHT22,23.7,64
// 2024-01-15T10:10:00,DHT22,23.6,65"

// Output:
{
  "payload": {
    "data": [
      { "timestamp": "2024-01-15T10:00:00", "sensor": "DHT22",
        "temperature": "23.5", "humidity": "65" },
      { "timestamp": "2024-01-15T10:05:00", "sensor": "DHT22",
        "temperature": "23.7", "humidity": "64" },
      { "timestamp": "2024-01-15T10:10:00", "sensor": "DHT22",
        "temperature": "23.6", "humidity": "65" }
    ]
  }
}

// Flow: [file-read log.csv] → [csv-parser] → [split] → [dashboard]

Example: Tab-Separated Values

Parse a TSV file using tab as the delimiter character.

// csv-parser node configuration
{
  "action": "parse",
  "delimiter": "\t",
  "hasHeader": true
}

// Input TSV data (tab-separated):
// "id\tname\tvalue
// 1\tTemperature\t23.5
// 2\tHumidity\t65.0"

// Output:
{
  "payload": {
    "data": [
      { "id": "1", "name": "Temperature", "value": "23.5" },
      { "id": "2", "name": "Humidity", "value": "65.0" }
    ]
  }
}

Example: Export Data to CSV

Convert an array of objects into CSV format for file export or download.

// csv-parser node configuration
{
  "action": "stringify",
  "delimiter": ","
}

// Input array in msg.payload.data:
{
  "payload": {
    "data": [
      { "device": "sensor-01", "temp": 23.5 },
      { "device": "sensor-02", "temp": 24.1 }
    ]
  }
}

// Output CSV string in msg.payload.data:
// "sensor-01,23.5
// sensor-02,24.1"

// Flow: [collect data] → [csv-parser stringify] → [file-write report.csv]

Common Use Cases

Data Import

Parse CSV files exported from spreadsheets and databases

Sensor Logs

Process historical sensor data stored in CSV format

Report Generation

Export collected data as CSV for analysis in Excel or Python

Data Migration

Convert between CSV and other formats (JSON, database)

Related Nodes