Reputation: 1217
I am trying to parse a CSV file using NodeJS. so far I have tried these packages:
I would like to parse a CSV file into objects based on header. I have been able to accomplish this with fast-csv but I have "'" values in my CSV file that I would like to ignore. I cant seem to do this with fast-csv even though I try to use the
{escape:'"'}
I used ya-csv to try to get around this but no values are being written when I try:
var reader = csv.createCsvFileReader('YT5.csv', {columnsFromHeader:true, 'separator': ','});
var writer = new csv.CsvWriter(process.stdout);
reader.addListener('YT5', function(data){
writer.writeRecord(data);
});
I get no output, any help would be great. Thanks.
Edit: I want the output in this format....
{ 'Video ID': '---kAT_ejrw',
'Content Type': 'UGC',
Policy: 'monetize',
'Video Title': 'Battlefield 3 Multiplayer - TDM na Kanałach Nouszahr (#3)',
'Video Duration (sec)': '1232',
Username: 'Indmusic',
Uploader: 'MrKacu13',
'Channel Display Name': 'MrKacu13',
'Channel ID': '9U6il2dwbKwE4SK3-qe35g',
'Claim Type': 'Audio',
'Claim Origin': 'Audio Match',
'Total Views': '11'
}
The header line is this.
Video ID,Content Type,Policy,Video Title,Video Duration (sec),Username,Uploader,Channel Display Name,Channel ID,Claim Type,Claim Origin,Total Views,Watch Page Views,Embedded Player Views,Channel Page Video Views,Live Views,Recorded Views,Ad-Enabled Views,Total Earnings,Gross YouTube-sold Revenue,Gross Partner-sold Revenue,Gross AdSense-sold Revenue,Estimated RPM,Net YouTube-sold Revenue,Net AdSense-sold Revenue,Multiple Claims?,Category,Asset ID,Channel,Custom ID,ISRC,GRid,UPC,Artist,Asset Title,Album,Label
All of these values will be filled in with some areas like title having single quotes.
This looks a mess so let me know if you need another format.
Upvotes: 4
Views: 8411
Reputation: 1217
This was resolved by using ya-csv
In order to use this I had to do a little more research but I did not know to add another listener for the data that I wanted to read and that it was just called 'data'
var reader = csv.createCsvFileReader('YT5.csv', {columnsFromHeader:true, 'separator': ','});
var writer = new csv.CsvWriter(process.stdout);
reader.addListener('data', function(data){
do something with data
}
reader.addListener('end', function(){
console.log('thats it');
}
This read the file without any issues from the single quotes.
Upvotes: 2