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

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

    jj is super-fast, can handle ginormous JSON documents economically, does not mess with valid JSON numbers, and is easy to use, e.g.

    jj -p # for reading from STDIN
    

    or

    jj -p -i input.json
    

    It is (2018) still quite new so maybe it won’t handle invalid JSON the way you expect, but it is easy to install on major platforms.

提交回复
热议问题