Living in the Shell #4; jq (JSON)

babakks

Babak K. Shandiz

Posted on November 26, 2021

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
πŸ’– πŸ’ͺ πŸ™… 🚩
babakks
Babak K. Shandiz

Posted on November 26, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related