1

I got the following results.

$ jq '.[].a,.[].b' <<< '[{"a": 1},  {"b": 2}]'
1
null
null
2
$ jq '.[] | select(.a or .b)' <<< '[{"a": 1},  {"b": 2}]'
{
  "a": 1
}
{
  "b": 2
}

But I want to search either "a" and "b" and the output that I would like is this.

1
2

What is the proper way to perform this or operation? Thanks.

peak
  • 105,803
  • 17
  • 152
  • 177
user1424739
  • 11,937
  • 17
  • 63
  • 152

1 Answers1

2

You can use alternate operator (//):

$ jq '.[] | .a//.b' <<< '[{"a": 1},  {"b": 2}]'
1
2
oguz ismail
  • 1
  • 16
  • 47
  • 69