4

I am trying to parse a CSV file using NodeJS. so far I have tried these packages:

Fast CSV

YA-CSV

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.

2
  • Could you provide an example of the .csv file you are trying to parse and the output you would like to have? Commented Nov 11, 2013 at 17:08
  • I just added an update, thanks Commented Nov 11, 2013 at 17:22

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.