Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save AndrewRayCode/caef6fc3991823fced0f to your computer and use it in GitHub Desktop.

Select an option

Save AndrewRayCode/caef6fc3991823fced0f to your computer and use it in GitHub Desktop.
NodeJS convert CSV to JSON object with headers
var csv = require('csv');
csv.parse(fs.readFileSync('./csv_with_headers.csv'), function(err, data) {
// Store the headers row
var headers = data[0];
// Remove the headers row
data.shift();
var objects = _.map(data, function(csvRow) {
// Combine the headers key with the csv data
return _.object(headers, csvRow);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment