{
"name": "value",
"website": "https://google.com",
"type" : "money",
"some": "0",
"something_else": "0",
"something_new": "0",
"test": [
{"Web" : "target1.com", "type" : "2" },
{"Web" : "target2.com", "type" : "3" },
{"Web" : "target3.com", "type" : "3" },
{"Web" : "target3.com", "type" : "3" }
]
}
我知道jq -r .test [] .Web将输出:
target1.com
target2.com
target3.com
但是如果我只想获得类型为3的值意味着输出只显示target2.com和target3.com
解决方法:
$jq -r '.test[] | select(.type == "3").Web' file.json
target2.com
target3.com
target3.com
这会将.test []节点传递给select,它使用.type ==“3”选择器过滤其输入.然后从过滤后的列表中选择.Web.