Read and Use JSON in Bash with jq

Cameron Nokes
InstructorCameron Nokes

Share this video with your friends

Send Tweet

Bash, unfortunately, doesn’t ship with a command that can work with JSON natively. In this lesson, we’ll learn how to read and do basic queries on JSON with jq, an installable command line tool that makes working with JSON in bash really easy. We'll pipe the JSON output of the Github API to jq to extract values.

Note: jq has to be installed. On macOS, the easiest way to do this is to run brew install jq. To view install instructions for all platforms, see https://stedolan.github.io/jq/download/.

Tre' Codez
Tre' Codez
~ 2 years ago

Hrmm, fails in zsh

echo ['1,2,3'] | jq '.[]'
zsh: no matches found: [1,2,3]
Cameron Nokes
Cameron Nokesinstructor
~ 2 years ago

Hrmm, fails in zsh

echo ['1,2,3'] | jq '.[]'
zsh: no matches found: [1,2,3]

It should be echo '[1,2,3]' | jq '.[]' with the single quotes surrounding the [].

Eliezer Steinbock
Eliezer Steinbock
~ 2 years ago

Hrmm, fails in zsh

echo ['1,2,3'] | jq '.[]'
zsh: no matches found: [1,2,3]

It should be echo '[1,2,3]' | jq '.[]' with the single quotes surrounding the [].

Both work in iTerm2.