Last active
          June 6, 2017 05:43 
        
      - 
      
 - 
        
Save williscool/2f9f6446499c69a215fd85362aae8e7d to your computer and use it in GitHub Desktop.  
Revisions
- 
        
williscool revised this gist
Jun 6, 2017 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,9 +14,11 @@ glob("*.json", options, function (er, files) { 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); });  - 
        
williscool renamed this gist
Jun 6, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
williscool created this gist
Jun 6, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ 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'))); let fields = ['date_journal','address', 'text']; let fieldNames = ['Date','Address', 'Note']; let csv = json2csv({ data: jsoned, fields: fields, fieldNames: fieldNames }); fs.writeFileSync('output.csv', csv); })