![](/img/trans.png)
[英]How to get a single value and value name from an JSON file without knowing the value name
[英]How to get name value in the below json file
[
{
"_class": "hudson.model.FreeStyleProject",
"name": "actual_build",
"url": "http://tepl.tallycloudinfra.com:8080/job/actual_build/",
"color": "blue",
"fullname": "actual_build"
},
{
"_class": "hudson.model.FreeStyleProject",
"name": "CIS_TEPL_QA_Deploy",
"url": "http://tepl.tallycloudinfra.com:8080/job/CIS_TEPL_QA_Deploy/",
"color": "blue",
"fullname": "CIS_TEPL_QA_Deploy"
},
{
"_class": "hudson.model.FreeStyleProject",
"name": "cktest",
"url": "http://tepl.tallycloudinfra.com:8080/job/cktest/",
"color": "red",
"fullname": "cktest"
},
{
"_class": "hudson.model.FreeStyleProject",
"name": "Create_New_DB_Structure",
"url": "http://tepl.tallycloudinfra.com:8080/job/Create_New_DB_Structure/",
"color": "blue",
"fullname": "Create_New_DB_Structure"
}
]
我在 jq 命令下嘗試了這個錯誤。
錯誤:
jq -r '._class[].name' f1.json
jq: error (at f1.json:30): Cannot index array with string "_class"
jq -r '._class.name' f1.json
jq: error (at f1.json:30): Cannot index array with string "_class"
有了您的輸入,
jq '.[].name' f1.json
產量
"actual_build"
"CIS_TEPL_QA_Deploy"
"cktest"
"Create_New_DB_Structure"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.