This is to add to of Gilles' Answer. There are many ways to get this done but personally I prefer something lightweight, easy to remember and universally available (e.g. come with standard LTS installations of your preferred Linux flavor or easy to install) on common *nix systems.
Here are the options in their preferred order:
Python Json.tool module
echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool
pros: almost available everywhere; cons: no color coding
jq (may require one time installation)
echo '{"foo": "lorem", "bar": "ipsum"}' | jq
cons: needs to install jq; pros: color coding and versatile
json_pp (available in Ubuntu 16.04 LTS)
echo '{"foo": "lorem", "bar": "ipsum"}' | json_pp
For Ruby users
gem install jsonpretty
echo '{"foo": "lorem", "bar": "ipsum"}' | jsonpretty