Skip to content

Instantly share code, notes, and snippets.

@tylor
Created March 7, 2012 23:03
Show Gist options
  • Select an option

  • Save tylor/1996996 to your computer and use it in GitHub Desktop.

Select an option

Save tylor/1996996 to your computer and use it in GitHub Desktop.
JSON to CSV
var fs = require('fs');
var csv = require('csv');
var data = fs.readFileSync('all_reports.json', 'utf8');
var lines = data.split("\n");
var all = [];
for (var i = 0; i < lines.length; i++) {
console.log(i);
var items = JSON.parse(lines[i]).items;
for (var j = 0; j < items.length; j++) {
all.push(items[j]);
}
}
csv()
.from(all)
.toStream(process.stdout, {end: false});
{
"name": "json2csv",
"version": "0.0.1",
"engines": {
"node": ">=0.4.9"
},
"dependencies": {
"csv": "0.0.11"
},
"scripts": { "start" : "node index.js" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment