I am reading a csv file and following are csv file data
name, age, addr1 , addr2
test, 20 , "unit 1, test address, epp" , "test address 2"
Now i am making an object using header. see below code
var lines = loadedstring.split('\n');
console.log(JSON.stringify(lines));
var headers = lines[0].split(',');
var jsonObj = [];
for (var i = 1; i < lines.length; i++) {
var data = lines[i].split(',');
var obj = {};
for (var j = 0; j < data.length; j++) {
obj[headers[j].trim()] = data[j].trim();
}
jsonObj.push(obj);
}
console.log(JSON.stringify(jsonObj));
Butt problem is that how can i handle the commas which are in double as you see above in sample data. I want to ignore all the commas which are in double quotes. Don't want to split if comma within double quote.