Created
March 7, 2012 23:03
-
-
Save tylor/1996996 to your computer and use it in GitHub Desktop.
JSON to CSV
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 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}); |
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
| { | |
| "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