title: How can I tell if a jq filter successfully pulls data from a JSON data structure?
body: <p>I want to know if a given filter succeeds in pulling data from a JSON data structure.  For example:</p>
  
  <pre><code>###### For the user steve...
  
  % Name=steve
  % jq -j --arg Name "$Name" '.[]|select(.user == $Name)|.value' &lt;&lt;&lt;'
  [
     {"user":"steve", "value":false},
     {"user":"tom", "value":true},
     {"user":"pat", "value":null},
     {"user":"jane", "value":""}
  ]'
  false
  % echo $?
  0
  </code></pre>
  
  <p><strong>Note:</strong> successful results can include boolean values, <code>null</code>, and even the empty string.</p>
  
  <pre><code>###### Now for user not in the JSON data...
  
  % Name=mary
  % jq -j --arg Name "$Name" '.[]|select(.user == $Name)|.value' &lt;&lt;&lt;'
  [
     {"user":"steve", "value":false},
     {"user":"tom", "value":true},
     {"user":"pat", "value":null},
     {"user":"jane", "value":""}
  ]'
  % echo $?
  0
  </code></pre>
  
  <p>If the filter does not pull data from the JSON data structure, I need to know this. I would prefer the filter to return a non-zero return code. </p>
  
  <p>How would I go about determining if a selector successfully pulls data from a JSON data structure vs. fails to pull data?</p>
  
  <p><strong>Important:</strong> The above filter is just an example, the solution needs to work for any jq filter.</p>
  
  <p><strong>Note:</strong> the evaluation environment is Bash 4.2+.</p>