如果密钥存在,则在 Ansible 中删除 json 对象

Strip json object in Ansible if key exists

假设我有一个这样的 json 对象:

{
 "results": [ 
    {
    "failed": "no",
    "data": "another string"
    },
    "failed": "no", 
    "skipped": true
    }
 }

有没有办法去除任何在 ansible 剧本中定义了 "skipped" 的对象的 json?所以我只想

{
 "results": [ 
    {
    "failed": "no",
    "data": "another string"
    }
}

使用rejectattr过滤器:

{ results | rejectattr('skipped') | list }

正在回答文字请求:

strip the json of any object that has "skipped" defined

{{ results | rejectattr('skipped','defined') | list }