How to prettyprint a JSON file?

前端 未结 13 1037
滥情空心
滥情空心 2020-11-22 01:53

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

13条回答
  •  庸人自扰
    2020-11-22 02:17

    Pygmentize + Python json.tool = Pretty Print with Syntax Highlighting

    Pygmentize is a killer tool. See this.

    I combine python json.tool with pygmentize

    echo '{"foo": "bar"}' | python -m json.tool | pygmentize -l json
    

    See the link above for pygmentize installation instruction.

    A demo of this is in the image below:

提交回复
热议问题