Easy Guide to Installing jq on MacOS with Homebrew
Written on
Chapter 1: Introduction to jq
Installing jq on your Mac is quite straightforward, especially if you have Homebrew set up.
Before diving into the installation, you might wonder what jq is and why it’s beneficial. According to jq's official site, it succinctly explains its capabilities:
jq operates similarly to sed, but for JSON data. It allows you to slice, filter, map, and transform structured data with the same ease that tools like sed, awk, and grep offer for text. Written in portable C, jq requires no runtime dependencies, allowing you to download a single binary and transfer it to a compatible machine without any issues. It can effortlessly convert your data into the desired format, often with shorter and simpler commands than one might expect.
Section 1.1: Checking Homebrew Installation
To verify if Homebrew is installed, execute the following command in your terminal:
$ brew
If Homebrew is present, you will see output similar to this:
$ brew
Example usage:
brew search TEXT|/REGEX/
brew info [FORMULA|CASK...]
brew install FORMULA|CASK...
brew update
brew upgrade [FORMULA|CASK...]
brew uninstall FORMULA|CASK...
brew list [FORMULA|CASK...]
Troubleshooting:
brew config
brew doctor
brew install --verbose --debug FORMULA|CASK
Contributing:
brew create URL [--no-fetch]
brew edit [FORMULA|CASK...]
Further help:
brew commands
brew help [COMMAND]
man brew
If Homebrew is not installed, you’ll see an error message like this:
zsh: command not found: brew
In this case, you will need to install Homebrew. Thankfully, I have a guide for that.
Section 1.2: Installing jq
Once you have verified that Homebrew is installed, you can easily install jq by running the following command:
$ brew install jq
After a successful installation, you can confirm it by executing:
$ jq
The output should look like this:
jq - commandline JSON processor [version 1.6]
Usage: jq [options] [file...]
jq [options] --args [strings...]
jq [options] --jsonargs [JSON_TEXTS...]
jq serves as a tool for processing JSON inputs, applying filters to the JSON text inputs, and generating results in JSON format on standard output. The simplest filter is ., which simply copies the input to the output without modifications (though formatting may change).
Example Usage
To see jq in action, you can try the following command:
$ echo '{"foo": 0}' | jq .
The output will be:
{
"foo": 0
}
To explore more options, use:
$ jq --help
And just like that, you have successfully installed jq!
Chapter 2: Helpful Video Tutorials
To further assist you in the installation and usage of jq, here are two informative video tutorials.
The first video, titled "Install jq on MacOS (Mojave, Catalina, Big Sur etc) using brew," provides a detailed walkthrough of the installation process.
The second video, "Video-4 | Installation and Jq Command Usage Help | By NarendraP," offers additional guidance on using jq effectively.