Skip to content

Instantly share code, notes, and snippets.

@timkock
Last active January 25, 2016 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkock/746d2ce94a4f6074c9a3 to your computer and use it in GitHub Desktop.
Save timkock/746d2ce94a4f6074c9a3 to your computer and use it in GitHub Desktop.
json re-formatter
// 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