Created
February 5, 2016 14:01
-
-
Save janschumann/e6632cbd765692f41547 to your computer and use it in GitHub Desktop.
Read JSON from stdin and pretty print
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
var json = ""; | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('readable', () => { | |
var chunk = process.stdin.read(); | |
if (chunk !== null) { | |
json += `${chunk}`; | |
} | |
}); | |
process.stdin.on('end', () => { | |
console.log(JSON.stringify(JSON.parse(json), null, 2)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
$ curl http://my.json/exaample | node pretty.js