Home » How-To » How to install jq on Ubuntu

How to install jq on Ubuntu

The “jq” is a command that’s based on the JSON processor.

It allows you to transform, slice, map, filter, or perform other operations on JSON data.

By default, jq reads JSON entities (e.g., numbers, literals) from stdin.

You can use whitespace to separate entities like 1 and 2 or true and false.

In this guide, you’ll learn how to install jq on Ubuntu, test it, or uninstall it.

How to install jq on Ubuntu

To install jq on Ubuntu, you need to run these respective commands, “sudo apt update”, “sudo apt install -y jq”, and “jq –version” (optional).

Step 1: Download package info from all configured sources

sudo apt update

Step 2: Install jq on Ubuntu

sudo apt install -y jq

Step 3: Check jq version

jq --version

Source: Ubuntu Manuals.

How to test jq on Ubuntu

1. Example JSON data

echo '{"status":"success","data":[{"name":"Tom","age":21},{"name":"Mary","age":24}]}' > test.json

2. The “.” filter prints well-formatted JSON

jq '.' test.json

3. The output of the command

{
  "status": "success",
  "data": [
    {
      "name": "Tom",
      "age": 21
    },
    {
      "name": "Mary",
      "age": 24
    }
  ]
}

4. Retrieving a specific JSON object/element

jq '.data[1].name' test.json

5. The output of the command

"Mary"

How to uninstall jq on Ubuntu

To uninstall jq on Ubuntu, you need to run the following command, “sudo apt purge –autoremove -y jq”.

How to uninstall jq:

sudo apt purge --autoremove -y jq

Further reading

What is LD_LIBRARY_PATH?

How to Fix “python: can’t open file ‘manage.py’: [Errno 2] No such file or directory”

How to Fix “TypeError: ‘type’ object is not subscriptable”

About the author

Lim How Wei

Lim How Wei is the founder of followchain.org, with 8+ years of experience in Social Media Marketing and 4+ years of experience as an active investor in stocks and cryptocurrencies. He has researched, tested, and written hundreds of articles ranging from social media platforms to messaging apps.

Lim has been quoted and referenced by major publications and media companies like WikiHow, Fast Company, HuffPost, Vice, New York Post, The Conversation, and many others. One of his articles about the gig economy was quoted by Joe Rogan who hosts The Joe Rogan Experience (arguably the most popular podcast in the world), in the This Past Weekend podcast by Theo Von.

In his free time, Lim plays multiple games like Tower of Fantasy, League of Legends, Counter-Strike, Hearthstone, RuneScape, and many others. He creates guides, walkthroughs, solutions, and more on games that he plays to help other players with their progression.