Search code examples
javascriptjquerycsvjquery-csv

Jquery CSV Library - Doesn't parse CSV file, if values are inside quotes


I am using jquery CSV library (https://github.com/evanplaice/jquery-csv/) , to parse and convert a CSV file into an array of objects. This is my code

this.parsedData = $.csv.toObjects(data);

if (this.parsedData.length === 0) {
**console.log('In valid'); /**/ This gets printed 
} else {
    console.log('valid')
}

My CSV file is this:

""__stream_code","project_code","process","due_date","root_table"
"DASH_PLAY_001","DEV","Plate",2013-02-02,"stream"
"DASH_PLAY_001","DEV","DepthAssess",2013-02-03,"stream""

Now, if I remove quotes, it works fine, but with quotes it doesn't. Most of the time, my application is going to handle CSV with values in quotes. Is there any way to fix it?


Solution

  • Try with http://papaparse.com/; you can parse it online and it works great.

    All you have to do is call through var results = $.parse(csvString);

    and it will return the JSON object for you.