How to Pretty Print JSON on the Command Line

JSON is a very popular platform independent data format. One of the great benefits of working with JSON is that it is generally easy to read. However, reading JSON objects becomes more difficult as the objects become large, especially on the command line. Pretty printing JSON records on the command line makes reading it much easier.

Pretty printing JSON records on the command line is easy to do with jq. jq is a lightweight command line JSON processor. jq is easy to install on Linux, Mac, and Windows, and can easily be used with other command line utilities such as sed, awk, grep, etc.

To simply pretty print JSON with jq, use the . filter. This filter just takes input and outputs it unchanged. jq by default will pretty print all output.

Here is an example using jq to pretty print a JSON object:

For more information about jq, please visit the the official site https://stedolan.github.io/jq/.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">