如何根据数组中的值选择JQ中的项目 [英] How to select items in JQ based on value in array
本文介绍了如何根据数组中的值选择JQ中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的文件:
{"items":["blue","green"]}
{"items":["yellow","green"]}
{"items":["blue","pink"]}
如何使用 jq 选择并仅显示在其中具有蓝色"的JSON值他们的项目"数组?
How can I use jq to select and show only the JSON values that have "blue" in their "items" array?
所以输出将是:
{"items":["blue","green"]}
{"items":["blue","pink"]}
推荐答案
找出答案
jq 'select(.items | index("blue"))'
这篇关于如何根据数组中的值选择JQ中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文