How can I pretty format a JSON file, with all the correct indents and everything?
Use jq a very good JSON processor and from personal preference, its the best available in the market
for just pretty print, use
jq . file_name
If you don't want to install an additional package and have python available you can do:
python -m json.tool myfile.json
It also supports reading from STDIN
Use the package yajl
, Yet Another JSON Library. On CentOS 7 it is located in the base repo, and is most probably already installed on the machine.
To pretty-print a JSON file:
cat myfile.json | json_reformat
or simply
json_reformat < myfile.json
To verify that a file is in correct JSON syntax:
json_verify < myfile.json