[英]How to extract data using jq
I am trying to use jq to extract data from JSON fields that contain a specific value.我正在尝试使用 jq 从包含特定值的 JSON 字段中提取数据。
This is the JSON that I'm working with:这是我正在使用的 JSON:
"results": [
{
"input": {
"FUZZ": "actuator",
"HOST": "https://zzlckzc4kz-3.algolia.net"
},
"position": 13,
"status": 301,
"length": 162,
"words": 5,
"lines": 8,
"redirectlocation": "https://algolia.net/1/404",
"resultfile": "",
"url": "https://zzlckzc4kz-3.algolia.net/actuator"
},
{
"input": {
"FUZZ": "actuator/heapdump",
"HOST": "https://zzlckzc4kz-3.algolia.net"
},
"position": 24,
"status": 301,
"length": 162,
"words": 5,
"lines": 8,
"redirectlocation": "https://algolia.net/1/404",
"resultfile": "",
"url": "https://zzlckzc4kz-3.algolia.net/actuator/heapdump"
},
]
i want the output to be if "status": 301 then display "url:"我希望输出为 if "status": 301 然后显示 "url:"
Try the following, assuming the file containing that json document is at /tmp/json
:尝试以下操作,假设包含该 json 文档的文件位于
/tmp/json
:
jq '.results[] | select(.status==301) | .url' /tmp/json
Also, I notice the document you supplied in the question is not actually a valid JSON document.另外,我注意到您在问题中提供的文档实际上不是有效的 JSON 文档。 I assume you meant the following:
我假设你的意思如下:
{
"results": [
{
"input": {
"FUZZ": "actuator",
"HOST": "https://zzlckzc4kz-3.algolia.net"
},
"position": 13,
"status": 301,
"length": 162,
"words": 5,
"lines": 8,
"redirectlocation": "https://algolia.net/1/404",
"resultfile": "",
"url": "https://zzlckzc4kz-3.algolia.net/actuator"
},
{
"input": {
"FUZZ": "actuator/heapdump",
"HOST": "https://zzlckzc4kz-3.algolia.net"
},
"position": 24,
"status": 301,
"length": 162,
"words": 5,
"lines": 8,
"redirectlocation": "https://algolia.net/1/404",
"resultfile": "",
"url": "https://zzlckzc4kz-3.algolia.net/actuator/heapdump"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.