socialyzehub

How to Install jq(JSON Processor) on Ubuntu 22.04 LTS (Jammy Jellyfish)

In this article, I will take you through the steps to install jq(JSON Processor) on Ubuntu 22.04 LTS (Jammy Jellyfish). jq is a free and open source command line JSON Processor for Linux/Unix based systems. It is lightweight and very flexible in usage. jq is written in Portable C and it runs independently on the system. jq filters and queries the given json data and then show the output in a structured format. It can be easily used with other commands using pipe operator and can also be used in scripting such as shell scripting. The output from jq can be written to a file or to the standard output. More on official website.

 

How to Install jq(JSON Processor) on Ubuntu 22.04 LTS (Jammy Jellyfish)

How to Install jq(JSON Processor) on Ubuntu 22.04 LTS (Jammy Jellyfish)

Also Read: How to Install curl on Ubuntu 22.04 LTS (Jammy Jellyfish)

Step 1: Prerequisites

a) You should have a running Ubuntu 22.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your Server.

 

Step 2: Update Your Server

In the very first step, you should first install all the available updates from default Ubuntu repo by using sudo apt update command and then upgrade the packages to the latest version by using sudo apt upgrade command as shown below.

socialyzehub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for socialyzehub:
Hit:1 https://dl.google.com/linux/chrome/deb stable InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Hit:3 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Get:4 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:6 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [280 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu jammy-updates/main i386 Packages [469 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [993 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [731 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [211 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 DEP-11 Metadata [101 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [14.0 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [748 kB]
Get:14 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [147 kB]
...........................................................

 

Step 3: Install jq(JSON Processor)

In the next step, you can install jq utility from default Ubuntu repo by using sudo apt install jq command as shown below. This will download and install the package along with all its dependencies.

socialyzehub@ubuntu:~$ sudo apt install jq
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libjq1 libonig5
The following NEW packages will be installed:
jq libjq1 libonig5
0 upgraded, 3 newly installed, 0 to remove and 14 not upgraded.
Need to get 357 kB of archives.
After this operation, 1,087 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libonig5 amd64 6.9.7.1-2build1 [172 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libjq1 amd64 1.6-2.1ubuntu3 [133 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 jq amd64 1.6-2.1ubuntu3 [52.5 kB]
Fetched 357 kB in 2s (201 kB/s)
Selecting previously unselected package libonig5:amd64.
(Reading database ... 200831 files and directories currently installed.)
Preparing to unpack .../libonig5_6.9.7.1-2build1_amd64.deb ...
Unpacking libonig5:amd64 (6.9.7.1-2build1) ...
Selecting previously unselected package libjq1:amd64.
Preparing to unpack .../libjq1_1.6-2.1ubuntu3_amd64.deb ...
...........................................................

 

Step 4: Verify Installation

After successful installation, you can verify the installed files path by using dpkg -L jq command as shown below.

socialyzehub@ubuntu:~$ dpkg -L jq
/.
/usr
/usr/bin
/usr/bin/jq
/usr/share
/usr/share/doc
/usr/share/doc/jq
/usr/share/doc/jq/AUTHORS.gz
/usr/share/doc/jq/README
/usr/share/doc/jq/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/jq.1.gz
/usr/share/doc/jq/changelog.Debian.gz

 

Step 5: Check Version

You can also check the current installed version by using jq --version command as shown below.

socialyzehub@ubuntu:~$ jq --version
jq-1.6

 

Step 6: Using jq

Now that we have jq utility installed in our server, it is time to test the JSON Processor. For that we have a sample.json file as shown below.

socialyzehub@ubuntu:~$ cat sample.json
{
 "car": "Ferrari",
 "variant": "Petrol",
 "color": "Red"
}

To get the value of car from above JSON, you can run cat sample.json | jq .car command as shown below.

socialyzehub@ubuntu:~$ cat sample.json | jq .car
"Ferrari"

Similarly, to get the variant, you can run cat sample.json | jq .variant command as shown below.

socialyzehub@ubuntu:~$ cat sample.json | jq .variant
"Petrol"

 

Step 7: Uninstall jq

Once you are done using jq utility, you can choose to uninstall it from your system by using sudo apt remove jq command as shown below.

socialyzehub@ubuntu:~$ sudo apt remove jq
[sudo] password for socialyzehub:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libjq1 libonig5
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
jq
0 upgraded, 0 newly installed, 1 to remove and 14 not upgraded.
After this operation, 102 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 200848 files and directories currently installed.)
Removing jq (1.6-2.1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...

Leave a Comment