Reputation: 33
I've this json. I want to extract test fields which their values equal to true. I tried with jq and got that error, pls any fix ?
$- jq '.[].name | select(.[].test == "true")' ddd
jq: error (at ddd:12): Cannot iterate over string ("AA")
[
{
"name": "AA",
"program_url": "https://www.google.com",
"test": false
},
{
"name": "BB",
"program_url": "https://yahoo.com",
"test": true
}
]
Upvotes: 0
Views: 160
Reputation: 36033
Are you looking for this? It iterates over the array .[]
, select
s those item objects whose .test
field evaluates to true
(implicit), and traverses further down to the .name
field. Using the --raw-output
(or -r
) option renders the output raw text (instead of JSON string in this case).
jq -r '.[] | select(.test).name' ddd
BB
Upvotes: 2