Skip to content

Instantly share code, notes, and snippets.

@RussellLuo
Last active May 12, 2017 06:27
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 RussellLuo/23b5116ed3593bfdb36265df4930ab2b to your computer and use it in GitHub Desktop.
Save RussellLuo/23b5116ed3593bfdb36265df4930ab2b to your computer and use it in GitHub Desktop.
JSON pretty printer in one line.
# 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