2017-05-31 75 views
1

我想取得一個字段值取決於另一個字段的值。如何過濾基於其他值的w/jq選擇的對象?

{ 
    "dirty": "false", 
    "instances": { 
     "random-generated-id-1": { 
     "state": "ON", 
     "id": "random-generated-id-1" 
     }, 
     "random-generated-id-2": { 
     "state": "OFF", 
     "id": "random-generated-id-2" 
     } 
    } 
} 

我想這是在ON狀態實例的id

jq ".instances"給我兩個實例。我怎樣才能得到random-generated-id-1

回答

4
jq -r '.instances[] | select(.state=="ON") | .id'