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

后端 未结 30 2994
孤独总比滥情好
孤独总比滥情好 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:22

    UPDATE I'm using jq now as suggested in another answer. It's extremely powerful at filtering JSON, but, at its most basic, also an awesome way to pretty print JSON for viewing.

    jsonpp is a very nice command line JSON pretty printer.

    From the README:

    Pretty print web service responses like so:

    curl -s -L http://t.co/tYTq5Pu | jsonpp
    

    and make beautiful the files running around on your disk:

    jsonpp data/long_malformed.json
    

    If you're on Mac OS X, you can brew install jsonpp. If not, you can simply copy the binary to somewhere in your $PATH.

提交回复
热议问题