[英]Using jq to extract certain info from JSON file
我从我的json文件中提取一些信息,格式如下:
{
"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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.