How can I pretty-print a JSON file from the comman

2019-01-21 12:45发布

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

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

Is there a shell script to format JSON to display file content in a readable form?

I've seen this post, and I think is a good starting point!

My idea is to iterate rows in the file and then:

while read row; do echo ${row} | python -mjson.tool; done < "file_name"

Does anyone have any other ideas?

7条回答
The star\"
2楼-- · 2019-01-21 13:25

Shawn's solution but for Python 3:

echo '{"foo": "bar"}' | python3 -m json.tool
查看更多
登录 后发表回答