title: Check for objects in JSON other than the one mentioned in a condition
body: <p>I need to check if there are exit codes other than <code>0</code> in the JSON file below.</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;domains&quot;: {
          &quot;app1&quot;: {
              &quot;status&quot;: &quot;Running&quot;
          },
          &quot;app2&quot;: {
              &quot;status&quot;: &quot;Terminated&quot;,
              &quot;exit code&quot;: 2
          },
          &quot;app3&quot;: {
              &quot;status&quot;: &quot;Running&quot;
          },
          &quot;app4&quot;: {
              &quot;status&quot;: &quot;Running&quot;
          },
          &quot;app5&quot;: {
              &quot;status&quot;: &quot;Terminated&quot;,
              &quot;exit code&quot;: 0
          }
      }
  }
  </code></pre>
  <p>Upon finding exit code other than <code>0</code>, I want the Ansible task to fail. I tried the following code:</p>
  <pre class="lang-yaml prettyprint-override"><code>- name: Execute command to obtain json list.
    command: cat test.json
    register: result
  
  - name: save the Json data to a Variable as a Fact
    set_fact:
       jsondata: &quot;{{ result.stdout | from_json }}&quot;
  
  - name: Find string
    when: jsondata.stdout is search('Terminated')
    debug:
       msg: &quot;{{ jsondata.stdout }}&quot;
    failed_when: &quot;{{ jsondata.stdout | jsonquery(domains.*[exit code] != 0) }}&quot;
  </code></pre>
  <p>But, this does not seem to work.</p>