python:json格式化输出
参考:https://stackoverflow.com/questions/12943819/how-to-prettyprint-a-json-fileimport jsonyour_json = '["foo", {"bar":["baz", null, 1.0, 2]}]'parsed = json.loads(your_json)print(json.dumps(parsed, inde
·
参考:
https://stackoverflow.com/questions/12943819/how-to-prettyprint-a-json-file
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
]
}
]
"""
总结:
加indient、sort_keys参数
更多推荐
已为社区贡献11条内容
所有评论(0)