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”

The post How to install jq on Ubuntu appeared first on Followchain.



* This article was originally published here

Comments

Popular Posts