![](/img/trans.png)
[英]How do I transform this JSON data using JQ to extract each nested array element to the top level in turn?
[英]How to extract data using jq
我正在尝试使用 jq 从包含特定值的 JSON 字段中提取数据。
这是我正在使用的 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"
},
]
我希望输出为 if "status": 301 然后显示 "url:"
尝试以下操作,假设包含该 json 文档的文件位于/tmp/json
:
jq '.results[] | select(.status==301) | .url' /tmp/json
另外,我注意到您在问题中提供的文档实际上不是有效的 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"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.