Cyberithub

How to Install jq(JSON Processor) on Debian 10/11

Advertisements

In this article, I will take you through the Steps to install jq(JSON Processor) on Debian 10/11. According to official documentation, jq is a lightweight and flexible command-line JSON processor. It is like sed for JSON data - you can use it to slice, filter, map and transform structured data with the same ease that sed, awk and grep let you play with text. It is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.

jq(JSON processor) can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you'd expect. One can use this tool from both the command line and with the scripts.

Advertisements

How to Install jq(JSON Processor) on Debian 10/11

How to Install jq(JSON Processor) on Debian 10/11

Also Read: 2 Ways to List all Manually Installed Packages in Ubuntu/Debian

Step 1: Prerequisites

a) You should have a running Debian 10/11 System.

Advertisements

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

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

Advertisements

 

Step 2: Update Your Server

It is always better to first update your installed packages with the latest version available from the Debian repo using apt update command. This command will sync your System packages with the latest available updates from the repo.

root@debian:~# apt update
Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease
Hit:3 http://deb.debian.org/debian bullseye-updates InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done

 

Step 3: Install jq tool

In the next step, you can install jq utility by using apt install jq -y command as shown below. This will download and install jq utility along with its dependencies from configured Debian repo.

Advertisements
root@debian:~# apt install jq -y
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 1 not upgraded.
Need to get 384 kB of archives.
After this operation, 1,148 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 libonig5 amd64 6.9.6-1.1 [185 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 libjq1 amd64 1.6-2.1 [135 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 jq amd64 1.6-2.1 [64.9 kB]
Fetched 384 kB in 1s (727 kB/s)
Selecting previously unselected package libonig5:amd64.
(Reading database ... 141498 files and directories currently installed.)
Preparing to unpack .../libonig5_6.9.6-1.1_amd64.deb ...
Unpacking libonig5:amd64 (6.9.6-1.1) ...

 

Step 4: Check  jq version

If you want to check the installed version of jq utility then you need to use jq --version command as shown below. As you can see the current version of jq is 1.6.

root@debian:~# jq --version
jq-1.6

 

Step 5: Using jq Utility

It is now time to test the jq utility by using a small example. Here we are having a small JSON file called user.json whose content looks like below. This JSON file contains the information about user admin.

root@debian:~# vi user.json
{
"user" : "admin",
"Modifieddate" : "Nov 10, 2019 10:56:10 PM GMT",
"Accesseddate" : "Nov 10, 2019 10:56:10 PM GMT"
}

Now if you want to access the value of user then you need to use jq .user user.json command as shown below.

root@debian:~# jq .user user.json
"admin"

 

Step 6: Remove jq Utility

Once you are done using jq utility, you can simply remove it by using apt remove jq -y command as shown below.

root@debian:~# apt remove jq -y
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 'apt autoremove' to remove them.
The following packages will be REMOVED:
jq
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 113 kB disk space will be freed.
(Reading database ... 141527 files and directories currently installed.)
Removing jq (1.6-2.1) ...
Processing triggers for man-db (2.9.4-2) ...

Leave a Comment