Skip to main content

Parse CSV Input


You want to parse CSV data to work with the values it contains.


The CSV node can be used to parse CSV and generate JavaScript objects from it.



[{"id":"73e4e16.4d9742","type":"inject","z":"64133d39.bb0394","name":"Inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":780,"wires":[["2bef78fd.ae70f8"]]},{"id":"90ed51dc.dcc71","type":"csv","z":"64133d39.bb0394","name":"","sep":",","hdrin":true,"hdrout":false,"multi":"mult","ret":"\\n","temp":"","skip":"1","x":410,"y":780,"wires":[["9aace6e7.adc538"]]},{"id":"9aace6e7.adc538","type":"debug","z":"64133d39.bb0394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":780,"wires":[]},{"id":"2bef78fd.ae70f8","type":"template","z":"64133d39.bb0394","name":"CSV data","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"# This is some random data\na,b,c\n80,18,2\n52,36,10\n91,18,61\n32,47,65","output":"str","x":260,"y":780,"wires":[["90ed51dc.dcc71"]]}]


In the example, the flow injects a payload containing CSV data:

# This is some random dataa,b,c80,18,252,36,1091,18,6132,47,65

The CSV has been configured to ignore the first line of the input so it ignores the initial comment line. It then uses the next line to get the column names, and the remaining rows for the data.

In this particular example, the node has also been configured to send a single message with all of the data. This results in a message with the payload:

[    { a: 80, b: 18, c: 2},    { a: 52, b: 36, c: 10},    { a: 91, b: 18, c: 61},    { a: 32, b: 47, c: 65},]

It is also possible to configure the node to emit one message for each row of data. In this mode, the messages will also include the property that allows them to be passed to a Join node to reassemble them back into a single array.