I can get the 1st element in json inside []
$ echo '[{"a":"x", "b":true}, {"a":"XML", "b":false}]' | jq '.[1]' { "a": "XML", "b": false }
But if json is already parsed (for example, after filtering records using "select"), how can I select one record and avoid the error visible here?
$ echo '[{"a":"x", "b":true}, {"a":"x", "b":false},{"a":"XML", "b":false}]' | jq '.[] | select( .a == "x")' { "a": "x", "b": true } { "a": "x", "b": false } $ echo '[{"a":"x", "b":true}, {"a":"x", "b":false},{"a":"XML", "b":false}]' | jq '.[] | select( .a == "x") | .[1]' jq: error (at <stdin>:1): Cannot index object with number
source share