假设我有一个类似以下的 JSON,但包含更多数据和更多嵌套
{
"dont_want_1": {
"a": 1
},
"dont_want_2": {
"b": 2
},
"find_me_1": [
{ "similarly_interesting_1": "this is a string" },
{ "similarly_interesting_2": "this is a string" },
{ "find_me_2": "look for me" },
{ "similarly_interesting_3": "this is a string" },
{ "similarly_interesting_4": "this is a string" }
],
"dont_want_3": {
"c": 3
},
"dont_want_4": {
"d": 4
}
}
我希望最终获得一堆具有 的类似对象jq
(最终结果将是similarly_interesting_1
及其兄弟对象)。我知道我想寻找一个值为 的对象look for me
。在这种情况下,运行类似的东西find_obj data.json "look for me"
应该会返回类似的东西find_me_1[2].find_me_2
。从该输出中,我可以运行cat data.json | jq '.find_me_1[]'
以获取所有这些对象。
$ cat data.json | jq '.find_me_1[]'
{
"similarly_interesting_1": "this is a string"
}
{
"similarly_interesting_2": "this is a string"
}
{
"find_me_2": "this a a string abc please look for me"
}
{
"similarly_interesting_3": "this is a string"
}
{
"similarly_interesting_4": "this is a string"
}
有没有办法find_str
用类似的标准工具来做到这一点jq
?