Skip to content

Instantly share code, notes, and snippets.

@callerobertsson
Created May 26, 2015 06:56
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 callerobertsson/b55b8379a2781be3f742 to your computer and use it in GitHub Desktop.
Save callerobertsson/b55b8379a2781be3f742 to your computer and use it in GitHub Desktop.
Javascript: JSON Formatter
// jsonformat.js
// a simple script that format JSON data in a more readable way.
// by Calle Robertsson, calle@upset.se, 2015.
var fs = require('fs');
var filename = process.argv[2];
if (!filename) {
throw new Error('Missing command line argument for file name.');
}
fs.readFile(filename, 'utf8', function (err, data) {
if (err) throw err;
parse(data);
});
function parse(text) {
var foo = JSON.parse(text);
console.log(JSON.stringify(foo, null, 2));
}
// eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment