Search code examples
node.jsnode-red

Convert text content to JSON using CSV node in NODE_RED?


Can any one help me how can we pass input with multiple lines to CSV node which has different columns/elements for each line.

I have a text file with below content

H|1|2|3|$|4|4
D|3|4|5
D|4|4|6
D|2|3|4

Here,how can we pass columns names for H-header,D-details differently to CSV node which generated JSON.

Thanks in advance!!


Solution

  • The best you can do is to use a switch node to split lines based on the first character and then run those lines through 2 separate CSV nodes.

    enter image description here

    The 2 CSV node can contain the header names for different line types.

    The switch node should be configured something like this:

    enter image description here

    You can then combine the 2 legs of the flow again to consume the different messages for the output of the CSV nodes.