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

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

    JSONLint has an open-source implementation on GitHub that can be used on the command line or included in a Node.js project.

    npm install jsonlint -g
    

    and then

    jsonlint -p myfile.json
    

    or

    curl -s "http://api.twitter.com/1/users/show/user.json" | jsonlint | less
    

提交回复
热议问题