How to install and use 'jq' on Windows

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
2 min

banner

# How to install and use 'jq' on Windows

jq is not installed by default on Windows, so if you try to use it, you'd get the "'jq' is not recognized as an internal or external command" error.

jq is not recognized as internal or external command

The easiest way to install jq is to use Chocolatey.

To install jq on Windows, if you have Chocolatey installed:

  1. Click on the Search bar and type PowerShell.

  2. Right-click on the PowerShell application and click "Run as administrator".

run powershell as administrator

  1. Run the following commands to install jq and curl.
PowerShell
choco install jq -y choco install curl -y
If you don't have Chocolatey installed, you have to install it first.

To install Chocolatey:

  1. Open PowerShell as an administrator.

run powershell as administrator

  1. Run the following command.
PowerShell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

windows install chocolatey

  1. Wait for the command to complete.
  2. Type choco to make sure Chocolatey is installed.

windows verify chocolatey installed

Now that you have Chocolatey installed, run the following commands to install jq and curl.

PowerShell
choco install jq -y choco install curl -y

Note that your shell should still be run using elevated permissions.

chocolatey install jq

Make sure jq is installed with the jq --version command.

Git
jq --version

Alternatively, you can install jq using Git Bash.

# Install jq using Git Bash

To install jq using Git Bash, you have to open Git Bash as an administrator.

To run Git Bash as an administrator:

  1. Click on the Search bar and type "Git Bash".
  2. Right-click on the "Git Bash" application and click "Run as administrator".

run git bash as administrator

  1. Issue the following command.
GitBash
curl -L -o /usr/bin/jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe

install jq git bash

Make sure jq is installed with the jq --version command.

Git
jq --version

git bash verify jq installed

# Using jq on Windows

The most common way to use jq is to issue an HTTP request and pipe the response to jq to extract some information from it.

First, look at the response type of the API.

cmd
curl "https://randomuser.me/api/"

You can access the results property by piping the response to jq.

cmd
curl "https://randomuser.me/api/" | jq ".results"

You can access the first object in the list by accessing the element at index 0.

cmd
curl "https://randomuser.me/api/" | jq ".results[0]"

You can then access specific properties on the response object.

cmd
curl "https://randomuser.me/api/" | jq ".results[0].email"

The command returns the email property of the first object in the results list.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.