Install jq on Ubuntu 22.04

Install jq on Ubuntu 22.04

JSON is a text-based data format which is widely used for storing or exchanging data between systems. The jq is a command line based JSON processor that allows to transform, filter, slice, map, or perform other operations on JSON data.

This tutorial demonstrates how to install jq on Ubuntu 22.04.

Install jq

Run the following commands to update the package lists and install jq:

sudo apt update
sudo apt install -y jq

When installation is finished, check jq version:

jq --version

Testing jq

Let's say we have JSON data stored in the test.json file:

echo '{"status":"success","data":[{"name":"John","age":25},{"name":"James","age":29}]}' > test.json

The jq tool supports various filters that can be applied on JSON data. For example, the dot . filter prints unchanged but nicely formatted JSON.

jq '.' test.json

The output of the command:

  "status": "success",
  "data": [
      "name": "John",
      "age": 25
      "name": "James",
      "age": 29

We can retrieve a particular field of JSON object or an element of JSON array as follows:

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



Uninstall jq

If you wish to completely remove jq and related dependencies, run the following command:

sudo apt purge --autoremove -y jq

The 1 Comment Found

Leave a Comment

Cancel reply

Your email address will not be published.