title: Delete different nested object if parent meets condition
body: <p>I want to delete different sub-objects from a json file (whilst maintaining the original structure) depending on whether the parent object's key meets a given condition.</p>
  <p>Say I have:</p>
  <pre><code>{
    &quot;A&quot;: {
      &quot;1&quot;: {
        &quot;bar&quot;: 1,
        &quot;foo&quot;: 0
      }
    },
    &quot;B&quot;: {
      &quot;2&quot;: {
        &quot;not_here&quot;: 0,
        &quot;foo&quot;: 0
      },
      &quot;3&quot;: {
        &quot;bar&quot;: 0,
        &quot;foo&quot;: 1
      }
    },
    &quot;C&quot;: {
      &quot;4&quot;: {
        &quot;bar&quot;: 0,
        &quot;foo&quot;: 1
      }
    }
  }
  </code></pre>
  <p>And for all nested objects with keys in [&quot;1&quot;, &quot;2&quot;], I want to delete the <code>bar</code> object, and otherwise I want to delete the <code>foo</code> object, so the output expected being:</p>
  <pre><code>{
    &quot;A&quot;: {
      &quot;1&quot;: {
        &quot;foo&quot;: 0
      }
    },
    &quot;B&quot;: {
      &quot;2&quot;: {
        &quot;not_here&quot;: 0,
        &quot;foo&quot;: 0
      },
      &quot;3&quot;: {
        &quot;bar&quot;: 0
      }
    },
    &quot;C&quot;: {
      &quot;4&quot;: {
        &quot;bar&quot;: 0
      }
    }
  }
  </code></pre>
  <p>I would've thought this would work:</p>
  <pre><code>.[][] |= (if .key == (&quot;1&quot;, &quot;2&quot;) then del(.bar) else del(.foo) end)
  </code></pre>
  <p>But there's something wrong with my conditional I think as it just deletes <code>foo</code> everywhere.</p>