From Json structure, I want a specific dictionary. From key's color yellow or red, I add id value.
[
{
"id": "9b058640",
"type": "db",
"color": "red",
"host": "db1"
},
{
"id": "0u858640",
"type": "db",
"color": "yellow",
"host": "db2"
},
{
"id": "0ui9k40",
"type": "net",
"color": "red",
"host": "net1"
},
{
"id": "5ty87a",
"type": "net",
"color": "yellow",
"host": "net2"
}
]
So I want to get the X dictionary
X=(
['yellow']="9b058640 5ty87a"
['red']="9b058640 0ui9k40"
)
I could parse by value :
jq -c '.[] | select(.color | contains("red"))'