Created
November 16, 2019 13:25
-
-
Save ademidun/77f4eb6d92d176422a362a6759c68f8c to your computer and use it in GitHub Desktop.
Pretty Print a JSON file with bash and python
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
#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