How can I pretty-print a JSON file from the command line?
command-line, json, shell
Solution
Pipe the results from the file into the python json tool 2.6 onwards
python -m json.tool < 'file_name'
Problem
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?