Home > Back-end >  Getting a single value from JSON using jq
Getting a single value from JSON using jq

Time:07-27

I'm trying to understand the proper use of jq to parse .json output
I have this file:

{

    "collections":[
        {
            "id":"XXXXX-XXXX-XXXXX-XXXXX-XXXXXXX",
            "name":"Collection One",
            "owner":"me",
            "uid":"10020232-XXXXX-XXXX-XXXXX-XXXXX-XXXXXXX",
            "isPublic":false
        },
        {
            "id":"YYYYY-YYYY-YYYYY-YYYYY-YYYYYYY",
            "name":"Collection Two",
            "owner":"me",
            "uid":"10020232-YYYYY-YYYY-YYYYY-YYYYY-YYYYYYY",
            "isPublic":false
        },
        {
            "id":"ZZZZZ-ZZZZ-ZZZZZ-ZZZZZ-ZZZZZZZ",
            "name":"Collection Three",
            "owner":"me",
            "uid":"ZZZZZ-ZZZZ-ZZZZZ-ZZZZZ-ZZZZZZZ",
            "isPublic":false
        },
}

Can I somehow get the "uid" for the collection with "name" : "Collecion Three"
Anything like SELECT uid FROM collections WHERE "name" = "Collection Three"

Thank you all in advance

CodePudding user response:

jq has a select filter:

.collections[] | select(.name == "Collection Three").uid
  • Related