简体   繁体   中英

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"
  }
]

I tried below jq command i'm getting this error.

Error:

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"

With your input,

jq '.[].name' f1.json

yields

"actual_build"
"CIS_TEPL_QA_Deploy"
"cktest"
"Create_New_DB_Structure"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM