Home > Mobile >  Find if item with specific property is in JSON array
Find if item with specific property is in JSON array

Time:10-30

I have the following JSON array

[
  {
    "login": "foo",
    "id": 111
  },
  {
    "login": "bar",
    "id": 222
  },
  {
    "login": "foobar",
    "id": 333
  }
]

How can I leverage the jq (preferrably) to check whether the object with "login": "bar" is member of this array?

CodePudding user response:

Use any/1.

any(.login == "bar")

Online demo

  • Related