Bootstrap FreeKB - jq - Parse JSON file
jq - Parse JSON file

Updated:   |  jq articles

Let's say you have the following in a file named my.json.

{
  "data": {
    "greeting": [
      {
        "foo": "hello"
      },
      {
        "foo": "world"
      }
    ]
  }
}

 

Here is how you can parse my.json using jq on a Linux system.

~]$ jq my.json
{
  "data": {
    "greeting": [
      {
        "foo": "hello"
      },
      {
        "foo": "world"
      }
    ]
  }
}

 

To parse the "data" key.

~]$ jq .data my.json
{
  "greeting": [
    {
      "foo": "hello"
    },
    {
      "foo": "world"
    }
  ]
}

 

To parse the data and then greeting key.

~]$ jq .data.greeting my.json
[
  {
    "foo": "hello"
  },
  {
    "foo": "world"
  }
]

 

Or like this, since the greeting key contains a list.

~]$ jq ".data.greeting[]" my.json
[
  {
    "foo": "hello"
  },
  {
    "foo": "world"
  }
]

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c1176a in the box below so that we can be sure you are a human.