简体   繁体   中英

Getting a single value from JSON using jq

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

jq has a select filter:

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

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