JSON -使用jq获取所有匹配的对象



我正在尝试为IP地址白名单设置自动化。

JSON可以在这里找到:https://ip-ranges.atlassian.com/

我需要生成每个"项目"的列表在JSON中"product"包含"bitbucket"(例如).

curl https://ip-ranges.atlassian.com/ | jq -c '.items | select(.[].product | contains("bitbucket"))'

输出为

jq: error (at <stdin>:1834): array (["confluenc...) and string ("bitbucket") cannot have their containment checked

我在这里做错了什么?

上面URL的JSON小样本:

{
"syncToken": 1644822802,
"creationDate": "2022-02-14T07:13:22.789203",
"items": [
{
"direction": [
"ingress",
"egress"
],
"network": "3.26.128.128",
"mask_len": 26,
"region": [
"ap-southeast-2"
],
"mask": "255.255.255.192",
"product": [
"confluence",
"jira",
"bitbucket",
"opsgenie",
"statuspage",
"halp",
"trello"
],
"cidr": "3.26.128.128/26"
},.........

一切归功于pmf的解决方案

jq -r '.items[] | select(.product | contains(["bitbucket"]))? | .cidr'

相关内容

  • 没有找到相关文章

最新更新