Skip to content

Instantly share code, notes, and snippets.

@gabhi
Created March 17, 2015 21:01
Show Gist options
  • Save gabhi/6198f61fbf320f12b4e2 to your computer and use it in GitHub Desktop.
Save gabhi/6198f61fbf320f12b4e2 to your computer and use it in GitHub Desktop.
csv to json node js
var Converter=require("csvtojson").core.Converter;
var fs=require("fs");
var csvFileName="./test.csv";
var fileStream=fs.createReadStream(csvFileName);
//new converter instance
var csvConverter=new Converter({constructResult:true});
//end_parsed will be emitted once parsing finished
csvConverter.on("end_parsed",function(jsonObj){
console.log(jsonObj); //here is your result json object
});
//read from file
fileStream.pipe(csvConverter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment