How to iterate through a list of JSON response in Bash shell (Bash/Linux/ZShell/Mac)

Bryant Jimin Son
3 min readNov 8, 2021
Ever wonder how can you iterate through a list of JSON response in a shell scripting like Bash?

I was writing a Bash shell script file that needs to query an URL endpoint with a curl, which then returns a JSON object response. One thing I had to do it to extract a list of all “name” values from the JSON object looking like one below.

Now, I could do myself a favor and simplify the process by using more powerful options like Javascript, Python, etc. However, due to other constraints and circumstances, I assumed Bash shell script is the best option.

So, although I have some good knowledge with Bash, I got lazy and Googled how to “iterate through list of json in bash,” which then gave me the result like this.

As I Googled “iterate through list of json in bash”

As you can notice, I read through quite a bunch of results. However, none of the answer was quite satisfactory. For example, this answer was found in Stackoverflow as one of top results.

--

--

Bryant Jimin Son
Bryant Jimin Son

Written by Bryant Jimin Son

A cloud practitioner talking about technology, travels & career tips. But I will sometimes cover financial advises and some random stuffs.