0

Say I have a json object like this:

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

Is there a way to strip the json of any object that has "skipped" defined in an ansible playbook? So I would just have

{
 "results": [ 
    {
    "failed": "no",
    "data": "another string"
    }
}
techraf
  • 64,883
  • 27
  • 193
  • 198
CEamonn
  • 853
  • 14
  • 37

2 Answers2

1

Use rejectattr filter:

{ results | rejectattr('skipped') | list }
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
1

Answering the literal request:

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

{{ results | rejectattr('skipped','defined') | list }
techraf
  • 64,883
  • 27
  • 193
  • 198