title: jq select where property contains property by name
body: <p>I have a basic JSON structure:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;A&quot;: {
      &quot;Option1&quot;: {
        &quot;contains&quot;: {
           &quot;inner1&quot;: { ... },
           &quot;inner2&quot;: { ... },
           &quot;innerN&quot;: { ... }
        }
      }
  
      &quot;Option2&quot;: {
           &quot;innerX&quot;: { ... },
           &quot;innerY&quot;: { ... },
           &quot;innerZ&quot;: { ... }
      }
    }
  }
  </code></pre>
  <p>What I need is to select either <code>Option1</code> or <code>Option2</code> based on whether or not it contains user input.</p>
  <p>For example:</p>
  <ul>
  <li>If the user provides <code>inner1</code>, return the <code>Option1</code> object</li>
  <li>If the user provides <code>innerY</code> return the <code>Option2</code> object</li>
  <li>etc.</li>
  </ul>
  <p>I have been successful if the options were an array, but I cannot do this if they are objects themselves.</p>
  <p>I tried looking at <a href="https://stackoverflow.com/questions/43946092/how-to-recurse-with-jq-on-nested-json-where-each-object-has-a-name-property">this example using <code>descend</code></a> but didn't quite follow.</p>
  <hr />
  <h2 id="update-1-tv5d">Update 1</h2>
  <p>I got a sloppy means to do this and then reuse the expression:</p>
  <pre class="lang-sh prettyprint-override"><code>jq -r 'paths | select(.[-1] == &quot;inner1&quot;) | .[0:-2] | join(&quot;.&quot;)' myFile.json
  </code></pre>
  <p>I can store that in a variable and reuse it. But that seems sloppy. It's a workaround, though.</p>
  <p>To test that out I did this:</p>
  <pre class="lang-sh prettyprint-override"><code>jq .$(THAT_COMMAND_ABOVE) myFile.json
  </code></pre>