Rather than querying up to the value you're testing for, query up to the root object that contains the value you're querying on and the values you wish to select.
You need the object that contains both the id
and the name
.
$ jq --arg name 'James Brown' 'select(.details.name == $name).id' input.json