0

{ "count": 3, "next": "", "previous": "", "list": [{ "id": "X1", "name": "STAGING", "description": null, "context": "STAGING", "version": "1.0.0", "provider": "user0", "status": "PUBLISHED", "thumbnailUri": null }, { "id": "X2", "name": "STAGING", "description": null, "context": "STAGING", "version": "2.0.0", "provider": "user1", "status": "PUBLISHED", "thumbnailUri": null }, { "id": "X3", "name": "STAGING", "description": null, "context": "STAGING", "version": "3.0.0", "provider": "user2", "status": "CREATED", "thumbnailUri": null }], "pagination": { "total": 3, "offset": 0, "limit": 25 } }

above is my json - looking for solution where i could loop and get "id" for a given "Version"

for suppose the while i pass argument "Version" = 3.0.0 expecting the output to be as "X3"( which is the key value of "id"

and the json is output from a curl.

this is what i have tried but no error's x= curl(); - which gives me above json as output!

echo "$x" | jq -r 'map(select(any(.version[]; contains("3.0.0"))|not)|.id)[]'

and i see error below:

jq: error (at :1): Cannot index number with string "version"

  • Where, specifically, did you get stuck when trying to solve this yourself? – Charles Duffy Jun 16 '21 at 00:18
  • Also, how is the version given (is it something that can be passed as an argument to jq?). Do you want to do the "looping" in jq code, or in bash code? Either is possible; part of the point of insisting that you show your work is that your own code will provide more information about what kind of solution you're looking for. – Charles Duffy Jun 16 '21 at 00:18
  • ...closed this as duplicate of a question whose existing answers should teach what you need to know; if you have trouble applying them, consider [edit]ing this question with a [mre] demonstrating the attempt -- the first edit after a question is closed queues it for review and potential reopening. – Charles Duffy Jun 16 '21 at 00:22

0 Answers0