Hank Chow
Hank Chow

Reputation: 564

How to filter an list by the value of an inner dict with jq?

Giving the input JSON:

[
  {
    "name": "foo",
    "value": 1
  },
  {
    "name": "bar",
    "value": 1
  },
  {
    "name": "foo",
    "value": 2
  }
]

I'm trying to get the dicts with the name foo, so the expecting output is:

{
  "name": "foo",
  "value": 1
},
{
  "name": "foo",
  "value": 2
}

Upvotes: 3

Views: 2098

Answers (1)

pmf
pmf

Reputation: 36088

Try this

jq '.[] | select(.name == "foo")' 

Demo

Upvotes: 5

Related Questions