jq is powerful enough to express it in one query: it has variables (using <i>expr as name</i>) which make this thing at least vaguely feasible. That doesn&#x27;t mean you should, but you <i>could</i>:<p><pre><code>    .models
      | (.[]
        | if .title == &quot;farmers&quot;
          then
              (.fields | .[] | if .name == &quot;Fruits&quot; then .key else empty end)
                as $fruits
            | (.fields | .[] | if .name == &quot;Full name&quot; then .key else empty end)
                as $name
            | .entities
            | .[]
            | if .[ $name ] == &quot;Bob, the farmer&quot; then .[ $fruits ] else empty end
          else empty end)
            as $fruits
      | .[]
      | if .[&quot;title&quot;] == &quot;fruits&quot;
          then
             ( .fields | .[] | if .name == &quot;Name&quot; then .key else empty end) as $fruit_name
             | .entities | [ .[] | {(._id): .[$fruit_name]} ] | add as $lookup
             | $fruits | .[] | $lookup[.]
          else empty
        end
</code></pre>
(I&#x27;m not claiming this is the best way to write that query, but it&#x27;s the first one I came up with.)