Last active
June 6, 2017 05:43
-
-
Save williscool/2f9f6446499c69a215fd85362aae8e7d to your computer and use it in GitHub Desktop.
Journey Note 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
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