Created
May 26, 2015 06:56
-
-
Save callerobertsson/b55b8379a2781be3f742 to your computer and use it in GitHub Desktop.
Javascript: JSON 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
// jsonformat.js | |
// a simple script that format JSON data in a more readable way. | |
// by Calle Robertsson, [email protected], 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