How can I pretty-print JSON in a shell script?

后端 未结 30 2551
孤独总比滥情好
孤独总比滥情好 2020-11-22 16:27

Is there a (Unix) shell script to format JSON in human-readable form?

Basically, I want it to transform the following:

{ \"foo\": \"lorem\", \"bar\":         


        
30条回答
  •  清酒与你
    2020-11-22 17:17

    Pygmentize

    I combine Python's json.tool with pygmentize:

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

    There are some alternatives to pygmentize which are listed in my this answer.

    Here is a live demo:

提交回复
热议问题