Last active
May 12, 2017 06:27
-
-
Save RussellLuo/23b5116ed3593bfdb36265df4930ab2b to your computer and use it in GitHub Desktop.
JSON pretty printer in one 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
# Method 1 | |
# Pros: really short | |
# Cons: unicode will be escaped | |
echo '{"hello":"你好"}' | python -mjson.tool | |
# Method 2 | |
# Pros: avoid unicode escapes, output string is always UTF-8 encoded | |
# Cons: a little long | |
echo '{"hello":"你好"}' | python -c 'import json, sys; print(json.dumps(json.load(sys.stdin), ensure_ascii=False, indent=2).encode("utf-8"))' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment