title: bash: Iterating over members of a JSON array selected by index
body: <p>I'm using <code>jq</code> to parse a JSON file, extracting each JSON array in a series into a shell array.</p>
  
  <p>My current code looks like the following:</p>
  
  <pre><code>for ((i = 0; i &lt; ${#nvars[@]}; i++)); do
      v1=($(cat $INPUT | jq '."config"[i]."var1"[]'))
      echo $v1
  done
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>error: i is not defined
  </code></pre>
  
  <p>I also replaced</p>
  
  <pre><code>v1=($(cat $INPUT | jq '."config"[i]."var1"[]'))
  </code></pre>
  
  <p>with</p>
  
  <pre><code>v1=($(cat $INPUT | jq '."config"[$i]."var1"[]'))
  </code></pre>
  
  <p>still not working. Any idea? Any help is appreciated! </p>
  
  <hr>
  
  <p>Edit: Sample Input Data</p>
  
  <pre><code>{
      "config-vars":[
          {
              "var1":["v1","v2"],
              "var2":""
          },
          {
              "var1":["v3",""],
              "var2":"v4"
          }
      ]
  }
  </code></pre>