could someone please explain below warning?
input file is:
{
"env": "DC",
"hosts" :
[
{
"apt_update_last_success": "1495991703",
"architecture": "amd64",
"hostname": "h1"
},
{
"apt_update_last_success": "1495991703",
"architecture": "amd64",
"hostname": "h2"
},
{
"apt_update_last_success": "1496045706",
"architecture": "amd64",
"hostname": "h3"
},
{
"apt_update_last_success": "1496045705",
"architecture": "amd64",
"hostname": "h4"
},
{
"apt_update_last_success": "1496049305",
"architecture": "amd64",
"hostname": "h5"
},
{
"apt_update_last_success": "1496049307",
"architecture": "amd64",
"hostname": "h6"
}
]
}
the jq command returns what expected but also prints the warning I dont know why:
$ jq -r '.[][] | select(.hostname=="h6")' ddd.json
jq: error: Cannot iterate over string
{
"apt_update_last_success": "1496049307",
"architecture": "amd64",
"hostname": "h6"
}
please tell me how to get rid of this.
thank you.
The issue is in your notation .[][]. Your input is just an object but you are trying to present it as a "container" of "containers" .[][].
The right way is:
jq '.hosts[] | select(.hostname=="h6")' ddd.json
{
"apt_update_last_success": "1496049307",
"architecture": "amd64",
"hostname": "h6"
}
Besides, on jq 1.5 this jq -r '.[][] | select(.hostname=="h6")' ddd.json doesn't return the expected object but only prints
jq: error (at jq1:36): Cannot iterate over string ("DC")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With