Last active
May 12, 2017 06:27
-
-
Save RussellLuo/23b5116ed3593bfdb36265df4930ab2b to your computer and use it in GitHub Desktop.
Revisions
-
RussellLuo revised this gist
May 12, 2017 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1,9 @@ # 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"))' -
RussellLuo renamed this gist
May 12, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ echo '{"hello":"你好"}' | python -c 'import json, sys; print(json.dumps(json.loads(sys.stdin.read()), ensure_ascii=False, indent=2).encode("utf-8"))' -
RussellLuo created this gist
May 12, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ echo '{"hello":"你好"}' | python -c 'import json, sys; print(json.dumps(json.loads(sys.stdin.read()), ensure_ascii=False, indent=2))'