Skip to content

Instantly share code, notes, and snippets.

@ademidun
Created November 16, 2019 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademidun/77f4eb6d92d176422a362a6759c68f8c to your computer and use it in GitHub Desktop.
Save ademidun/77f4eb6d92d176422a362a6759c68f8c to your computer and use it in GitHub Desktop.
Pretty Print a JSON file with bash and python
#source: https://stackoverflow.com/a/1920585/5405197
# With Python 2.6+ you can just do:
echo '{"foo": "lorem", "bar": "ipsum"}' | python -m json.tool
#or, if the JSON is in a file, you can do:
python -m json.tool my_json.json
#if the JSON is from an internet source such as an API, you can use
curl http://my_url/ | python -m json.tool
#For convenience in all of these cases you can make an alias:
alias prettyjson='python -m json.tool'
#For even more convenience with a bit more typing to get it ready:
prettyjson_s() {
echo "$1" | python -m json.tool
}
prettyjson_f() {
python -m json.tool "$1"
}
prettyjson_w() {
curl "$1" | python -m json.tool
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment