Read and Use JSON in Bash with jq

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
~ 5 years ago

Hrmm, fails in zsh

echo ['1,2,3'] | jq '.[]'
zsh: no matches found: [1,2,3]
Cameron Nokesinstructor
~ 5 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
~ 5 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.

mstmustisnt
~ 2 years ago

I had to wrap the url into the double quotes, I was getting curl -s https://api.github.com/search/repositories?q=service+worker zsh: no matches found: https://api.github.com/search/repositories?q=service+worker otherwise