根据使用对象变量JQ价值选择对象 [英] Select objects based on value of variable in object using jq
本文介绍了根据使用对象变量JQ价值选择对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的JSON文件:
I have the following json file:
{
"FOO": {
"name": "Donald",
"location": "Stockholm"
},
"BAR": {
"name": "Walt",
"location": "Stockholm"
},
"BAZ": {
"name": "Jack",
"location": "Whereever"
}
}
我使用JQ,并希望得到其中位置是斯德哥尔摩对象的名的元素。
I am using jq and want to get the "name" elements of the objects where 'location' is 'Stockholm'.
我知道我可以通过
cat json | jq .[] | jq ."name"
"Jack"
"Walt"
"Donald"
但我无法弄清楚如何给一个子键的值只打印特定的对象,(此处位置:斯德哥尔摩
)。
推荐答案
在谷歌上搜索地段发现主要的jQuery的东西,我发现了一个博客帖子的答案是:
After lots of googling finding mainly jQuery stuff, I found a blog post with the answer:
$ jq '.[] | select(.location=="Stockholm")' json
{
"location": "Stockholm",
"name": "Walt"
}
{
"location": "Stockholm",
"name": "Donald"
}
从这里开始:<一href=\"http://zerokspot.com/weblog/2013/07/18/processing-json-with-jq/\">http://zerokspot.com/weblog/2013/07/18/processing-json-with-jq/
这篇关于根据使用对象变量JQ价值选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文