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

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

    The JSON Ruby Gem is bundled with a shell script to prettify JSON:

    sudo gem install json
    echo '{ "foo": "bar" }' | prettify_json.rb
    

    Script download: gist.github.com/3738968

提交回复
热议问题