-
-
Save xmas/d06f89389bd53d463b6af9d98c0073ce to your computer and use it in GitHub Desktop.
Read JSON from standard input and writes formatted JSON to standard output. Requires Node.js.
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
#!/usr/bin/env node | |
// Reads JSON from stdin and writes equivalent | |
// nicely-formatted JSON to stdout. | |
var stdin = process.stdin, | |
stdout = process.stdout, | |
inputChunks = []; | |
stdin.resume(); | |
stdin.setEncoding('utf8'); | |
stdin.on('data', function (chunk) { | |
inputChunks.push(chunk); | |
}); | |
stdin.on('end', function () { | |
var inputJSON = inputChunks.join(), | |
parsedData = JSON.parse(inputJSON), | |
outputJSON = JSON.stringify(parsedData, null, ' '); | |
stdout.write(outputJSON); | |
stdout.write('\n'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment