使用 jq 获取数组中的键等于特定值的数组?
我一直在练习 jq play 来尝试获取列表中的所有数组,其中 website 是 ==“google”,并从中创建另一个 json 列表。
https://jqplay.org/s/DKNC2mhOLq
jq:错误(位于:18):无法索引包含字符串“website”的数组 exit status 5
{
"items": [
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"2",
"website":"jingle"
}
]
所需的输出:
[
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"1",
"website":"google"
}
]
如何循环遍历列表中的数组并查找特定键的特定值?感谢您提供的任何帮助或想法。我是 JSON 和 jq 的初学者。
I have been practicing with jq play to try to get all the arrays in a list where website is == "google" and create another json list from that.
https://jqplay.org/s/DKNC2mhOLq
jq: error (at :18): Cannot index array with string "website"
exit status 5
{
"items": [
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"2",
"website":"jingle"
}
]
Desired output:
[
{
"name":"name1",
"id":"1",
"website":"google"
},
{
"name":"name1",
"id":"1",
"website":"google"
}
]
how can I loop through arrays in a list and look for specific values for specific keys? Thanks for any help or ideas you can provide. I am a begginer with JSON and jq.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
select
用map
括起来,因为您希望将过滤器单独应用于每个数组项,同时保留周围的数组结构。演示
Enclose the
select
with amap
, as you want to apply the filter to each array item individually while retaining the surrounding array structure.Demo