Compact but pretty JSON output in python?

JSON is written either with indent=None(by default) as one line (unreadable to the human eye), or with a ident=Nnew line after each comma.

What I would like to see is a more compact, but still fairly simple conclusion, similar to what ordinary Lisp does with beautiful printing. For example, 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"
 }

I would like to see

 {
  "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"
 }

similar to what it pprintproduces.

+3
source share

Source: https://habr.com/ru/post/1688163/


All Articles