I have a callback where i am getting the below console output when printing row.
output of row [ 'Name', 'Language' ]
output of row [ 'English', 'Fr' ]
output of row [ 'German', 'Gr' ]
output of row [ 'France', 'London' ]
I want to convert the above array into a valid json excluding the first row alone like this.
{
"English" : "Fr",
"German" : "Gr",
"France" : "London"
}
.on('record', function(row, index){
console.log("output of row", row);
var obj = {};
row.forEach(function(column, index) {
obj[row[index].trim()] = row[index].trim();
})
record.push(obj);
}
})
Additional Code
I am getting csv data which i am pushing it into a row each time. Below is the CSV Data and the array i am getting each time i read the csv data...
Language,Name
Fr,English
Gr,German
London,France
output of row [ 'Name', 'Language' ]
output of row [ 'English', 'Fr' ]
output of row [ 'German', 'Gr' ]
output of row [ 'France', 'London' ]
cvcsv()
.from.string(csv)
.transform( function(row){
row.unshift(row.pop());
return row;
})
.on('record', function(row, index){
console.log("output of row",row)