查找jq过滤器以根据嵌套属性的值排除嵌套对象

时间:2016-12-17 06:17:31

标签: filter nested key jq

鉴于此输入:

{
  "10000703": {
    "show_id": 1641788,
  },
  "10000838": {
    "show_id": 1517903,
  },
  "10001325": {
    "show_id": 1641788,
  },
}

我正在寻找一个过滤器来说“返回show_id不等于1641788的所有对象”

预期输出为:

{
  "10000838": {
    "show_id": 1517903,
  },
}

无法排除嵌套对象:(

1 个答案:

答案 0 :(得分:3)

这是with_entries/1方便的一个很好的例子,以及jq可能的简洁性:

with_entries( select(.value.show_id != 1641788 ))

with_entries/1将对象转换为显式的.key / .value表示。有关详细信息,请参阅jq manual

或者更简洁,在这种情况下,也可以使用del/1

del( .[] | select( .show_id == 1641788 ) )
相关问题