Last active
January 25, 2016 07:45
-
-
Save timkock/746d2ce94a4f6074c9a3 to your computer and use it in GitHub Desktop.
json re-formatter
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
// npm install lodash glob | |
// dependencies | |
var glob = require('glob'); | |
var _ = require('lodash'); | |
var path = require('path'); | |
var fs = require('fs'); | |
// unformatted files are in a subfolder 'index' | |
// output subfolder 'parsed' has already been made | |
// node format.js will do the work | |
glob('index/*.json', function (err, files) { | |
var done = _.after(files.length, function () { | |
console.log('were done'); | |
}); | |
_.forEach(files, function (f) { | |
fs.readFile(path.join(__dirname, f), function (err, data) { | |
var js = JSON.parse(data); | |
fs.writeFile(path.join(__dirname, 'parsed', path.basename(f)), JSON.stringify(js, null, '\t'), done); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment