Last active
April 14, 2019 12:20
-
-
Save horttanainen/92dcf49c34d33f367ab90a72e7ac8da9 to your computer and use it in GitHub Desktop.
Prettify and transform json from command line
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 bash | |
JS=' | |
var toEval = process.argv[1]; | |
process.stdin.resume(); | |
process.stdin.setEncoding("utf8"); | |
var json = ""; | |
process.stdin.on("data", function(buf) { | |
json += buf; | |
}); | |
process.stdin.on("end", function() { | |
const obj = JSON.parse(json); | |
const modifiedJObj = eval(toEval); | |
console.log(JSON.stringify(modifiedJObj, null, 2)); | |
}); | |
' | |
node -e "$JS" -- "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use other packages as well (if you install them alongside the script):