Python中紧凑但漂亮的JSON输出? [英] Compact but pretty JSON output in python?

查看:286
本文介绍了Python中紧凑但漂亮的JSON输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON是用indent=None(默认)作为单行(人眼不可读)或在每个逗号之后用ident=N和换行符编写的.

JSON is written either with indent=None (default) as a single line (unreadable to a human eye) or with ident=N with a newline after each comma.

我希望看到的是更紧凑但仍很漂亮的输出,类似于Common Lisp漂亮的打印内容. 例如,而不是

What I would like to see is a more compact but still pretty output, similar to what Common Lisp pretty-printing does. E.g., instead of

 {
  "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 产生的结果.

similar to what pprint produces.

推荐答案

目前无法实现,但是当 RFE:实现了更紧凑的漂亮打印,此问题将通过使用 python-rapidjson .

This is not possible at this time, but when RFE: more compact pretty printing is implemented, this question will be answered by using python-rapidjson.

这篇关于Python中紧凑但漂亮的JSON输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆