This is the first part of an ongoing series on mastering jq. This series does not assume prior experience with jq, but it does assume basic fluency in shell programming.
jq is a valuable tool that every fast coder has in their tool chest. It contains depths of immense power. In part 1, we'll start off with the basics.
For each application of jq, we’ll lead off with an example that you can copy and paste into your shell to see how it works. The rest of the section discusses the application in more detail.
Pretty print json
echo '{"k1": [{"k2": [9]}]}' | jq '.'
One of the most valuable applications of jq is also the easiest to use: pretty printing json.
Pass the desired json on stdin to jq and it will print pretty print json on stdout. jq's pretty printing adds both shape and color to the data. Shape and color make the data much faster to read and debug as discussed in Debug With Your Eyeballs. One caveat is that jq will not render colors if jq's output is piped into another command or a fil…