티스토리 뷰

공부

[Python] beautify JSON

승가비 2020. 12. 10. 11:35
728x90
import json
print json.dumps({'4': 5, '6': 7}, sort_keys=True, ensure_ascii=False, indent=4)

{
    "4": 5,
    "6": 7
}

def pretty(obj):
    return json.dumps(
        obj,
        ensure_ascii=False,
        sort_keys=True,
        indent=4)

https://stackoverflow.com/questions/9105031/how-to-beautify-json-in-python

 

How to beautify JSON in Python?

Can someone suggest how I can beautify JSON in Python or through the command line? The only online based JSON beautifier which could do it was: http://jsonviewer.stack.hu/. I need to use it from ...

stackoverflow.com

https://stackoverflow.com/questions/12943819/how-to-prettyprint-a-json-file

 

How to prettyprint a JSON file?

I have a JSON file that is a mess that I want to prettyprint. What's the easiest way to do this in Python? I know PrettyPrint takes an "object", which I think can be a file, but I don't know how t...

stackoverflow.com

https://torbjorn.tistory.com/221

 

Python3 json dump 한글 깨짐 해결방법

파이썬에서 json dump를 했더니 한글이 유니코드로 저장된다. 이유를 찾아보니 dump 메소드는 기본적으로 ascii 형태로 저장하기 때문. json dump 메소드에 ensure_ascii=False를 넣어줘야 잘 저장된다.

torbjorn.tistory.com

 

728x90

'공부' 카테고리의 다른 글

[Python] dict to string  (0) 2020.12.10
[Python] call method by name of function  (0) 2020.12.10
[Spark] string to date  (0) 2020.12.10
[Spark] `foreach` vs `foreachPartition`  (0) 2020.12.10
[Sh] HDFS exists directory  (0) 2020.12.10
댓글