Created
March 21, 2016 11:34
-
-
Save Spaxe/759c4c83b85826dfa38a to your computer and use it in GitHub Desktop.
Simple NodeJS commandline script to convert JSON to CSV
This file contains 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
// Usage: | |
// node csv-converter.js input_path.json > output_path.csv | |
// | |
// Dependency: json-2-csv | |
if (process.argv.length < 3) process.exit(1); | |
var fs = require('fs'); | |
var json_2_csv = require('json-2-csv'); | |
fs.readFile(process.argv[2], {encoding: 'utf-8'}, function (err, data) { | |
if (err) throw err; | |
json_2_csv.json2csv(JSON.parse(data), function (err, csv) { | |
if (err) throw err; | |
console.log(csv); | |
}, { | |
delimiter: { | |
wrap: '"' | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment