简体   繁体   中英

jq: retrieve values from multiple entries

(I have searched, but found nothing.)

I have a (huge) json file I got from Jira, and I want to get from it several values from different entries, using curl via linux.

For example:

{
   "expand": "names, schema",
   "startAt":0,
   "maxResults":1,
   "total":46,
   "issues":[
      {
         "key":"ABCD-12345",
         "fields":{
            "updated":"2020-12-03T13:16:17.000+0200",
            "customfield_18484":null,
            "customfield_14687":null,
            "customfield_14688":null,
            "customfield_18800":null,
            "customfield_23380":"",
            "customfield_18480":"off"
         }
      }
   ]
}

And I want to get the key (ABCD-12345) and the updated (2020-12-03T13:16:17.000+0200).

Each command works separately, but I can't figure out how to combine them.

My commands:

curl -s -g -H "Content-Type: application/json" "<link to my jira with search parameters" -u "<user>:<password>" | jq '.issues[].key' | tr -d '"'

returns ABCD-12345

curl -s -g -H "Content-Type: application/json" "<link to my jira with search parameters" -u "<user>:<password>" | jq  '.issues[].fields | "\(.updated)"' | tr -d '"'

returns 2020-12-06T10:08:06.000+0200

I have tried several combinations, like: jq '.issues[].fields | "(.updated)"' | jq '.issues[].key' jq '.issues[].fields | "(.updated)", .issues[].key'

But they didn't work.

Any ideas? Thanks!

This should achieve what you wanted:

jq -r '.issues[] | .key+" "+.fields.updated'

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