티스토리 뷰

공부

[Python] pretty print JSON

seunggabi 승가비 2020. 8. 10. 22:33
import json

your_json = '["foo", {"bar":["baz", null, 1.0, 2]}]'
parsed = json.loads(your_json)
print(json.dumps(parsed, indent=4, sort_keys=True))
[
    "foo", 
    {
        "bar": [
            "baz", 
            null, 
            1.0, 
            2
        ]
    }
]

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

 

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

[Spark] SQL datediff  (0) 2020.08.11
[Java] convert integer to string with comma for thousands  (0) 2020.08.11
[Python] pretty print JSON  (0) 2020.08.10
[Presto] month ago  (0) 2020.08.10
[Java] @JsonProperty show `is` prefix  (0) 2020.08.10
[Sh] for  (0) 2020.08.10
댓글
댓글쓰기 폼