![](/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.