I&#x27;ve been meaning to learn jq, so I decided to give it a try.<p><pre><code>    FRUITS=$(cat input.json | jq &#x27;.models | map(select(.title == &quot;fruits&quot;)) | .[0]&#x27;)
    FRUIT_NAME_KEY=$(echo &quot;$FRUITS&quot; | jq &#x27;.fields | map(select(.name == &quot;Name&quot;)) | .[0].key&#x27;)
    
    FARMERS=$(cat input.json | jq &#x27;.models | map(select(.title == &quot;farmers&quot;)) | .[0]&#x27;)
    FARMER_NAME_KEY=$(echo &quot;$FARMERS&quot; | jq &#x27;.fields | map(select(.name == &quot;Full name&quot;)) | .[0].key&#x27;)
    FARMER_FRUITS_KEY=$(echo &quot;$FARMERS&quot; | jq &#x27;.fields | map(select(.name == &quot;Fruits&quot;)) | .[0].key&#x27;)
    
    BOB=$(echo &quot;$FARMERS&quot; | jq &#x27;.entities | map(select(.[&#x27;$FARMER_NAME_KEY&#x27;] == &quot;Bob, the farmer&quot;)) | .[0]&#x27;)
    BOB_FRUIT_IDS=$(echo &quot;$BOB&quot; | jq &#x27;.[&#x27;$FARMER_FRUITS_KEY&#x27;] | .[]&#x27; -r)
    
    for BOB_FRUIT_ID in &quot;$BOB_FRUIT_IDS&quot;; do
        echo &quot;$FRUITS&quot; | jq &#x27;.entities | map(select(._id == &quot;&#x27;$BOB_FRUIT_ID&#x27;&quot;)) | .[0] | .[&#x27;$FRUIT_NAME_KEY&#x27;]&#x27;
    done
</code></pre>
There&#x27;s a bit of bash boilerplate, but honestly it was about what I would expect, given a structure with so many layers of indirection.<p>Pain points:<p>* Switching between bash and jq&#x27;s filtering language led me to use string interpolation with bash variables. Malicious inputs can probably exploit this (and it was just awkward anyway).<p>* A &quot;select one&quot; filter would be nice, instead of select + get first element.