Last active
March 16, 2016 02:59
-
-
Save RichardHan/ba817019b76564cc8787 to your computer and use it in GitHub Desktop.
Unix shell pretty-print JSON in unix shell
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
# | |
# Use JSON.stringify | |
# | |
$ node -e "console.log(JSON.stringify(JSON.parse(process.argv[1]), null, '\t'));" \ | |
'{"key1":"value1","key2":"value2"}' | |
$ node -e "console.log(JSON.stringify(JSON.parse(require('fs') \ | |
.readFileSync(process.argv[1])), null, 4));" myjson.json | |
# ============================================================================================= | |
# | |
# With Python 2.6+ | |
# [for convenience you can make an alias] alias prettyjson='python -m json.tool' | |
# | |
$ echo '{"key1": "value1", "key2": "value2"}' | python -m json.tool | |
$ python -m json.tool my_json.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment