title: jq select compare two max's of array within object
body: <p>Let's say I have to following JSON file:</p>
  <pre><code>{
    &quot;1.1.1.1&quot;: {
      &quot;history_ban&quot;: [
        &quot;2021-05-02 14:30&quot;,
        &quot;2022-01-01 12:00&quot;
      ],
      &quot;history_unban&quot;: [
        &quot;2021-05-09 14:30&quot;,
        &quot;2022-01-08 12:00&quot;
      ]
    },
    &quot;2.2.2.2&quot;: {
      &quot;history_ban&quot;: [
        &quot;2022-01-16 07:00&quot;
      ],
      &quot;history_unban&quot;: []
    },
    &quot;3.3.3.3&quot;: {
      &quot;history_ban&quot;: [
        &quot;2022-01-15 22:40&quot;
      ]
    }
  }
  </code></pre>
  <p>My goals is to get all the keys where:</p>
  <ol>
  <li>Max history_ban date is smaller than &quot;2022-01-16 09:00&quot;</li>
  <li>Max history_unban date is empty/non-existent or smaller then Max history_ban date</li>
  </ol>
  <p>I believe I have the majority of the query working as I wanted, but the 'Compare max unban with max ban' is not working. My current (not working) query is as follows:</p>
  <pre><code>to_entries[] | select((.value.history_ban != null) and (.value.history_ban | max &lt; &quot;2022-01-16 09:00&quot;) and ((.value.history_unban | length == 0 ) or (.value.history_unban | max &lt; .value.history_ban | max))) | .key
  </code></pre>
  <p>I know my error is within <code>(.value.history_unban | max &lt; .value.history_ban | max)</code> because, if I replace it with <code>(.value.history_unban | max &lt; &quot;somedate&quot;)</code> I get a working query.</p>
  <p>The error I get is</p>
  <blockquote>
  <p>jq: error (at :22): Cannot index array with string &quot;value&quot;
  exit status 5</p>
  </blockquote>
  <p>What do I need to do to select/compare these two max values?</p>
  <p>Just to be sure, my expected result in this example is</p>
  <ul>
  <li>&quot;2.2.2.2&quot;</li>
  <li>&quot;3.3.3.3&quot;</li>
  </ul>