Skip to content

Instantly share code, notes, and snippets.

@Spaxe
Created March 21, 2016 11:34
Show Gist options
  • Save Spaxe/759c4c83b85826dfa38a to your computer and use it in GitHub Desktop.
Save Spaxe/759c4c83b85826dfa38a to your computer and use it in GitHub Desktop.
Simple NodeJS commandline script to convert JSON to CSV
// 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