Skip to content

Instantly share code, notes, and snippets.

@janschumann
Created February 5, 2016 14:01
Show Gist options
  • Save janschumann/e6632cbd765692f41547 to your computer and use it in GitHub Desktop.
Save janschumann/e6632cbd765692f41547 to your computer and use it in GitHub Desktop.
Read JSON from stdin and pretty print
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));
});
@janschumann
Copy link
Author

Usage:

$ curl http://my.json/exaample | node pretty.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment