Last active
August 29, 2015 14:20
-
-
Save AndrewRayCode/caef6fc3991823fced0f to your computer and use it in GitHub Desktop.
NodeJS convert CSV to JSON object with headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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