所以我已经阅读了jq
教程并使用了github
json
那里的响应并提取了其他一些键的一些值,所以我想我理解语法是如何工作的。不幸的是,尝试在 Googlesafe-browsing
json
响应中使用它时没有任何效果。以下是存储在变量中的完整响应(对于jq
教程中的 github 示例也是如此):
echo "$safeb"
{
"matches": [
{
"threatType": "MALWARE",
"platformType": "ALL_PLATFORMS",
"threat": {
"url": "http://www.wittyvideos.com"
},
"cacheDuration": "300s",
"threatEntryType": "URL"
}
]
}
...这就是我尝试过的:
echo "$safeb" | jq '.matches.threatType'
jq: error (at <stdin>:13): Cannot index array with string "threatType"
echo "$safeb" | jq '.threatType'
null
echo "$safeb" | jq '.[] | .threatType'
jq: error (at <stdin>:13): Cannot index array with string "threatType"
echo "$safeb" | jq '.[] | {type: .threatType}'
jq: error (at <stdin>:13): Cannot index array with string "threatType"
提前致谢。