I am trying to return a row value on a matching string.
I begin with a csv that doesn't have header details. After loading the csv into memory, I think I need to first add headers and then convert the data to json, then loop through the data to find the correct object in the array.
I have used highland to create a read stream and output to objects. However, the line break characters \r
and \r\n
are not getting parsed out and are injected into the value strings.
This approach also doesn't seem to parse the entire file, it is outputting 3 lines.
highland(fs.createReadStream('example.csv', 'utf8'))
.map(line => line.split(','))
.map(parts => ({
a: parts[0],
b: parts[1],
c: parts[2]
}))
.each(x => console.log(x))
It would be nice to structure the CSV as JSON and then use the .filter()
method to match the record.
Actual output of 1000+ line file
{ a: '', b: 'CD53110' }
{ a: '\nRD40115', b: 'CD40315' }
{ a: '', b: '63\r\nRE15468' }
{ a: '96798', b: '5\r\nRR60899' }
Example input snippet
,CD510,13
,T9069,65
RCM22,TC633,101
RC023,87693,16
M2024,T7636,109
Note: first few rows only contain 'b' and 'c' columns.