Install jsongrep on Ubuntu 26.04

Install jsongrep on Ubuntu 26.04

The jsongrep is a command-line tool for querying and extracting values from JSON, YAML, TOML, JSONL, and other serialization formats. It uses a JSONPath-inspired query language based on regular path expressions to efficiently search structured data. This tutorial demonstrates how to install jsongrep on Ubuntu 26.04.

Install jsongrep

Get the latest version number of jsongrep from the official GitHub repository:

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

Download archive using the previously retrieved version:

curl -sSLo jsongrep.tar.gz https://github.com/micahkepe/jsongrep/releases/latest/download/jsongrep-$JSONGREP_VERSION-x86_64-unknown-linux-musl.tar.gz

Unpack the archive into a temporary directory:

mkdir jsongrep-temp
tar xf jsongrep.tar.gz --strip-components=1 -C jsongrep-temp

Move the binary into /usr/local/bin:

sudo mv jsongrep-temp/jg /usr/local/bin

After installation, confirm that the tool is available:

jg --version

Clean up temporary files:

rm -rf jsongrep.tar.gz jsongrep-temp

Testing jsongrep

Create a sample JSON file for testing:

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

To display the JSON content in a formatted structure:

jg '' test.json

The output of the command:

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

To extract a specific value from the dataset:

jg --no-path 'data[1].name' test.json

Result:

"James"

Uninstall jsongrep

If jsongrep is no longer needed, remove it as follows:

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

Leave a Comment

Cancel reply

Your email address will not be published.