Skip to content

Instantly share code, notes, and snippets.

@williscool
Last active June 6, 2017 05:43
Show Gist options
  • Save williscool/2f9f6446499c69a215fd85362aae8e7d to your computer and use it in GitHub Desktop.
Save williscool/2f9f6446499c69a215fd85362aae8e7d to your computer and use it in GitHub Desktop.
Journey Note Json To Csv
const fs = require('fs');
const glob = require('glob');
const json2csv = require('json2csv');
const options = {};
glob("*.json", options, function (er, files) {
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
console.log(`Num of files: ${files.length}`);
let jsoned = files.map((f) => JSON.parse(fs.readFileSync(f, 'utf8')));
jsoned.forEach((o) => o.date_time = new Date(o.date_journal));
let fields = ['date_time','address', 'text'];
let fieldNames = ['Date','Address', 'Note'];
let csv = json2csv({ data: jsoned, fields: fields, fieldNames: fieldNames });
fs.writeFileSync('output.csv', csv);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment