0

How can I get the id value if name equals to y in cli?

JSON input :

{
  "items": [
    {
      "id": "x",
      "name": "y"
    }
  ]
}

I've tried this

json file | jq -r '.items | select(.name=="y")

it returns

jq: error (at :1): Cannot index array with string "name"` error

How to retrieve the value of name only via jq?

Thanks!

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
cosmos-1905-14
  • 783
  • 2
  • 12
  • 23
  • 1
    `.items[] | select(.name == "y").id` will output `x` – 0stone0 Nov 14 '22 at 19:37
  • As an aside, the pseudo-pipe `json file | ` is not correct. It looks like maybe you were trying to do a [useless use of `cat`](https://stackoverflow.com/questions/11710552/useless-use-of-cat) but botching it. – tripleee Nov 15 '22 at 05:38

0 Answers0