How to Install jq in Git Bash?

jq is a lightweight and flexible command-line JSON processor. It allows you to slice, filter, map, and easily transform structured data. This guide will walk you through installing jq in Git Bash on Windows.

Steps to Install jq

Step 1: Download jq

First, you need to download the jq executable for Windows. Follow these steps:

  1. Go to the jq download page.
  2. Scroll down to the Windows section.
  3. Click on the 64-bit or 32-bit link under the “Windows” heading, depending on your system architecture.
  4. This will download the jq.exe file.

Step 2: Move jq.exe to a Directory in Your PATH

To use jq from Git Bash, you need to place it in a directory that’s included in your system’s PATH. Follow these steps:

  1. Open your file explorer and navigate to the directory where you downloaded jq.exe.
  2. If the downloaded file name is not jq.exe, rename the file to jq.exe.
  3. Copy the jq.exe file.
  4. Paste jq.exe into a directory that’s in your system’s PATH. A common directory for this is C:\Program Files\Git\usr\bin. To do this:
    1. Navigate to C:\Program Files\Git\usr\bin.
    2. Paste jq.exe into this directory.

Step 3: Verify the Installation

To verify that jq has been installed correctly, open Git Bash and run the following command:

jq --version

If jq is installed correctly, this command will output the version of jq installed, for example:

jq version output in Git Bash

Implementation of jq in Git Bash

Now that you have installed jq, you can start using it to process JSON data. Here’s a simple example of how to use jq in Git Bash.

Example: Extracting Data from a JSON Object

Suppose you have the following JSON file named data.json:

{
"name": "John Doe",
"age": 30,
"city": "New York"
}

To extract the value of the “name” field, you can use the following jq command in Git Bash:

jq '.name' data.json

Explanation:

  • jq is the command to run jq.
  • '.name' is the jq filter to extract the “name” field from the JSON object.
  • data.json is the JSON file you are processing.

The command will output:

how to install jq in git bash