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

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

    bat is a cat clone with syntax highlighting:

    Example:

    echo '{"bignum":1e1000}' | bat -p -l json
    

    -p will output without headers, and -l will explicitly specify the language.

    It has colouring and formatting for JSON and does not have the problems noted in this comment: How can I pretty-print JSON in a shell script?

提交回复
热议问题