gpt4 book ai didi

python - python 中紧凑但漂亮的 JSON 输出?

转载 作者:太空狗 更新时间:2023-10-30 01:36:42 25 4
gpt4 key购买 nike

JSON 可以使用 indent=None(默认)作为单行(人眼无法读取)或使用 ident=N 在每个逗号后换行.

我希望看到的是更紧凑但仍然漂亮的输出,类似于 Common Lisp pretty-print 所做的。例如,而不是

 {
"cleanup":{
"cpu":6936.780000000001,
"wall":7822.319401979446
},
"finished":"2017-08-14 18:36:23",
"init":{
"cpu":1365.73,
"wall":1380.7802910804749
},
"job":"timings",
"run":{
"cpu":953.6700000000001,
"wall":8350.496850013733
},
"started":"2017-08-14 13:28:06"
}

我想看看

 {
"cleanup":{"cpu":6936.780000000001,"wall":7822.319401979446},
"finished":"2017-08-14 18:36:23",
"init":{"cpu":1365.73,"wall":1380.7802910804749},
"job":"timings",
"run":{"cpu":953.6700000000001,"wall":8350.496850013733},
"started":"2017-08-14 13:28:06"
}

类似于pprint产生。

最佳答案

目前这是不可能的,但是当RFE: more compact pretty printing已实现,将使用 python-rapidjson 回答此问题.

关于python - python 中紧凑但漂亮的 JSON 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45681702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com