Install jq on Raspberry Pi

Install jq on Raspberry Pi

JSON is a text-based data format that is widely used to store or exchange 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 shows how to install jq on Raspberry Pi.

Install jq

Connect to Raspberry Pi via SSH. Update the package lists and install jq using the following commands:

sudo apt update
sudo apt install -y jq

Once installed, check jq version:

jq --version

Testing jq

Now we can test. 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

Command will output:

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

We can get a particular field of JSON object or an element of JSON array:

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



Uninstall jq

If you want to completely remove jq and related dependencies that is not used by other packages, execute the following command:

sudo apt purge --autoremove -y jq

The 2 Comments Found

  1. Avatar
    SPS_Hubert Reply

    I used this with Tasmota devices.
    curl -s | jq -r .StatusSNS.ENERGY.Power

    Thank you,

Leave a Comment

Cancel reply

Your email address will not be published.