Skip to content

Instantly share code, notes, and snippets.

@AndersDJohnson
Last active June 5, 2019 13:32
Show Gist options
  • Save AndersDJohnson/10743525 to your computer and use it in GitHub Desktop.
Save AndersDJohnson/10743525 to your computer and use it in GitHub Desktop.
csvToJson
var csv = require('csv');
csv()
.from.path(__dirname+'/export.csv', { delimiter: ',', escape: '"' })
.to.array( function(data){
var labels = data.shift();
var items = [];
data.forEach(function (row) {
var item = {};
row.forEach(function (value, index) {
var label = labels[index];
item[label] = value;
});
items.push(item);
});
console.log(items);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment