> ## Content Index
> Fetch the complete content index at: https://undiluted.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# JSON Parsing in Bash
- URL: https://undiluted.org/json-parsing-in-bash/
- Published: 2019-09-15T00:01:49.000Z
- Updated: 2019-09-15T00:05:48.000Z
- Author: nic
- Tags: JSON, BASH, parsing, cli, linux, #Import 2026-09-02 19:24

About a month ago, I needed to parse [JSON](https://www.json.org/?ref=undiluted.org) from in [Bash](https://www.gnu.org/software/bash/?ref=undiluted.org) scripts.

This was an interesting problem/challenge, enter [./jq](https://stedolan.github.io/jq/?ref=undiluted.org).

[jq](https://stedolan.github.io/jq/?ref=undiluted.org) is a sed like tool for JSON data, that can be used to parse JSON, from the command line, and from within [Bash](https://www.gnu.org/software/bash/?ref=undiluted.org) scripts.

[jq](https://stedolan.github.io/jq/?ref=undiluted.org) is written in C, and is a single binary, that has zero runtime dependencies, meaning that you can simply download the binary and get parsing!

Some simple examples:

Lets say we have the following JSON payload:

```
sample.json:

[
  {
    "rank": 1,
    "description": "Great Search Engine",
    "url": "https://google.com"
  },
  {
    "rank": 2,
    "description": "Oldie but goodie",
  	 "url": "https://www.yahoo.com"
  }
]

```

If we wanted to print out the JSON payload in a colorized output, we could do:

```
cat sample.json | jq

```

The output would be:

![json-pretty-print](https://undiluted.org/content/images/2019/09/json-pretty-print.png)

Lets say we wanted just the URLs:

```
cat sample.json | jq .[].url

```

The output would be:

![json-just-urls](https://undiluted.org/content/images/2019/09/json-just-urls.png)

If we wanted just the first URL:

```
cat sample.json | jq .[0].url

```

This would ouput:

![json-just-first-url](https://undiluted.org/content/images/2019/09/json-just-first-url.png)

The URLs followed by the Ranks:

```
cat sample.json | jq '.[] | .url,.rank'

```

This would output:

![json-urls-ranks](https://undiluted.org/content/images/2019/09/json-urls-ranks.png)

Lets do something a little more complex, lets say we want to add **1** to every rank:

```
cat sample.json | jq '.[].rank +1'

```

This would output:

![json-rank-arithmetic](https://undiluted.org/content/images/2019/09/json-rank-arithmetic.png)

The above are just simple examples, [jq](https://stedolan.github.io/jq/?ref=undiluted.org) is very powerful, and can do much more!

I recommend checking out the [jq/](https://stedolan.github.io/jq/?ref=undiluted.org) github page to get more information on this great tool.