Install jaq on Ubuntu 24.04

Install jaq on Ubuntu 24.04

The jaq command line tool is an alternative to jq, which is widely known for processing JSON data. Both tools are designed to manipulate and transform JSON data, allowing users to parse, filter, and format JSON output in various ways. The jaq is optimized for speed and efficiency, making it a faster alternative in some cases. This tutorial explains how to install jaq on Ubuntu 24.04.

Install jaq

Fetch the latest version tag of the jaq release and store it in a variable:

JAQ_VERSION=$(curl -s "https://api.github.com/repos/01mf02/jaq/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download executable from GitHub releases page and place it in the /usr/local/bin directory:

sudo wget -qO /usr/local/bin/jaq https://github.com/01mf02/jaq/releases/latest/download/jaq-v$JAQ_VERSION-x86_64-unknown-linux-gnu

Set execute permission for file:

sudo chmod a+x /usr/local/bin/jaq

We can check jaq version with command:

jaq --version

Testing jaq

Suppose we have JSON data saved in the test.json file:

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

The jaq tool offers numerous filters for manipulating JSON data. For instance, the dot . filter outputs the JSON as-is, but in a nicely formatted manner.

jaq '.' test.json

Output:

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

We can extract a specific field from a JSON object or an element from a JSON array in the following way:

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

Output:

"James"

Uninstall jaq

To uninstall jaq, simply delete its associated file:

sudo rm -rf /usr/local/bin/jaq

Leave a Comment

Cancel reply

Your email address will not be published.