DEV Community

Cover image for Living in the Shell #4; jq (JSON)
Babak K. Shandiz
Babak K. Shandiz

Posted on • Originally published at babakks.github.io on

Living in the Shell #4; jq (JSON)

jq ๐Ÿงน

JSON formatter/prettifier.

๐Ÿ  https://stedolan.github.io/jq/
๐Ÿ“— https://github.com/stedolan/jq

Installation (on Debian)

sudo apt-get install jq
Enter fullscreen mode Exit fullscreen mode

Format/prettify

echo -n '{"who":["me","you"],"when":"now"}' | jq
Enter fullscreen mode Exit fullscreen mode
{
  "who": [
    "me",
    "you"
  ],
  "when": "now"
}

Indentation with tab --tab

echo -n '{"who":["me","you"],"when":"now"}' | jq --tab
Enter fullscreen mode Exit fullscreen mode

Compact -c

cat << EOF | jq -c
{
  "who": [
    "me",
    "you"
  ],
  "when": "now"
}
EOF
Enter fullscreen mode Exit fullscreen mode
{"who":["me","you"],"when":"now"}

Sort keys -S

echo -n '{"z":"z","a":"a"}' | jq -S
Enter fullscreen mode Exit fullscreen mode
{
  "a": "a",
  "z": "z"
}

Uncolorize output (monochrome) -M

echo -n '{"who":"me","when":"now"}' | jq -M
Enter fullscreen mode Exit fullscreen mode

Top comments (0)