title: jq: slicing array based on argument
body: <p>I am trying to slice an array in jq where the end index is passed as an argument from the shell (bash):</p>
  
  <pre><code>end_index=7
  cat obj.json | jq --arg eidx $end_index, '.arr[0:$eidx]'
  </code></pre>
  
  <p>This works as expected when the index is hard-coded</p>
  
  <pre><code>cat obj.json | jq '.arr[0:7]'
  </code></pre>
  
  <p>but in the example at the top, I get an error message</p>
  
  <pre><code>jq: error (at &lt;stdin&gt;:0): Start and end indices of an array slice must be numbers
  </code></pre>
  
  <p>I suspect this might be to do with how jq handles variable substitution within the slice operator <code>[:]</code>, but none of my attempts to solve the problem, e.g. by enclosing the variable name in curly braces <code>.arr[0:${eidx}]</code>, has worked.</p>