Suppose I have this JSON:
[
{
"k": foo,
"v": 1
},
{
"k": bar,
"v": 2
}
]
How to get the value for the "bar"
key?
You can use select(expr)
to find the object with a key-value "k":"bar"
and then you can extract the value of the "v"
key.
$ jq . test.json
[
{
"k": "foo",
"v": 1
},
{
"k": "bar",
"v": 2
}
]
$ jq -r '.[] | select(.k == "bar") | .v' test.json
2
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.