简体   繁体   中英

Get JSON Object by property with jq / bash

I have some JSON objects that looks like this

{
 "name": "thing1",
 "important_value": "42",
 "other_value": "27"
}
{
 "name": "thing2",
 "important_value": "13",
 "other_value": "5"
}
{
 "name": "thing3",
 "important_value": "788",
 "other_value": "58"
}

I need to get the value from only one of these object, but I only know the "name" value. I've tried somthing like this:

echo $objects | jq '.name == "thing2"'

I then get

false
true
false

But I need to get the values from this object, how do I achive this?

echo "$objects" | jq 'select(.name == "thing2")'

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