How can I pretty-print a JSON file from the command line?

后端 未结 13 1847
星月不相逢
星月不相逢 2020-12-07 14:32

I\'ve a file with a sequence of JSON element:

{ element0: \"lorem\", value0: \"ipsum\" }
{ element1: \"lorem\", value0: \"ipsum\" }
...
{ elementN: \"lorem\"         


        
13条回答
  •  孤街浪徒
    2020-12-07 15:03

    Formatting json as a table from the command line

    You can use jtab - a tool written in rust - to print any json data as a table.

    For example:

    ➜ echo '{"foo": "bar"}' | jtab
    
    +-----+
    | foo |
    +-----+
    | bar |
    +-----+
    

    It also works with a json array:

    ➜  echo '[{"id": "1", "name": "Rust"}, {"id": "2", "name": "Jtab"}]' | jtab
    
    +----+------+
    | id | name |
    +----+------+
    | 1  | Rust |
    +----+------+
    | 2  | Jtab |
    +----+------+
    

提交回复
热议问题