通过jq从嵌套json返回条目

问题描述 投票:0回答:1

对于给定的 json:

{
  "source_1": [
    {
      "val1": "foo1",
      "val2": "bar1"
    },
    {
      "val1": "foo2",
      "val2": "bar2"
    }
  ],
  "source_2": [
    {
      "val1": "foo1",
      "val2": "bar1"
    },
    {
      "val1": "foo3",
      "val2": "bar3"
    }
  ]
}

我想在

val2
==
bar1
处递归搜索它,但以这种格式返回它:

{
  "source_1": [
    {
      "val1": "foo1",
      "val2": "bar1"
    }
  ],
  "source_2": [
    {
      "val1": "foo1",
      "val2": "bar1"
    }
  ]
}
json jq
1个回答
0
投票

这会产生您预期的输出:

map_values(map(select(.val2 == "bar1")))
© www.soinside.com 2019 - 2024. All rights reserved.