title: Pass keys from array from bash into jq -- output all nulls
body: <p>I'm trying to do something akin to this:</p>
  <pre><code>jq -r  '. | .&quot;Time Series (Daily)&quot;.&quot;2020-12-02&quot; | .&quot;1. open&quot;' newdata.json
  </code></pre>
  <p>...but with the key coming from a variable, as in:</p>
  <pre><code>jq -r --arg key &quot;$key&quot; '. | .&quot;Time Series (Daily)&quot;.&quot;[$key]&quot; | .&quot;1. open&quot;' newdata.json
  </code></pre>
  <p>The first one works just fine, but when I assign the date to a variable called key and then try to get the data, it fails.</p>
  <p>I tried <a href="https://stackoverflow.com/questions/40027395/passing-bash-variable-to-jq">This answer</a> and <a href="https://stackoverflow.com/questions/34745451/passing-arguments-to-jq-filter">This answer</a>. But did not work for me.</p>
  <pre><code>{
      &quot;Meta Data&quot;: {
          &quot;1. Information&quot;: &quot;Daily Prices (open, high, low, close) and Volumes&quot;,
          &quot;2. Symbol&quot;: &quot;AB&quot;,
          &quot;3. Last Refreshed&quot;: &quot;2020-12-02&quot;,
          &quot;4. Output Size&quot;: &quot;Compact&quot;,
          &quot;5. Time Zone&quot;: &quot;US/Eastern&quot;
      },
      &quot;Time Series (Daily)&quot;: {
          &quot;2020-12-02&quot;: {
              &quot;1. open&quot;: &quot;32.6700&quot;,
              &quot;2. high&quot;: &quot;33.3300&quot;,
              &quot;3. low&quot;: &quot;32.5000&quot;,
              &quot;4. close&quot;: &quot;33.1200&quot;,
              &quot;5. volume&quot;: &quot;273799&quot;
          },
          &quot;2020-12-01&quot;: {
              &quot;1. open&quot;: &quot;32.1500&quot;,
              &quot;2. high&quot;: &quot;32.8000&quot;,
              &quot;3. low&quot;: &quot;32.0000&quot;,
              &quot;4. close&quot;: &quot;32.6000&quot;,
              &quot;5. volume&quot;: &quot;265086&quot;
          },
          &quot;2020-11-30&quot;: {
              &quot;1. open&quot;: &quot;32.3800&quot;,
              &quot;2. high&quot;: &quot;32.4900&quot;,
              &quot;3. low&quot;: &quot;31.7500&quot;,
              &quot;4. close&quot;: &quot;31.8700&quot;,
              &quot;5. volume&quot;: &quot;251970&quot;
          }
      }
  }
  </code></pre>
  <p>The above is the newdata.json file.
  What I want to get is the &quot;1. open&quot; value.
  I am using a for loop to iterate over all the keys of &quot;Time Series (Daily)&quot; and the keys are generated correctly. There is no issue with that. I then want to use the $key variable in each iteration to
  get the data I need.</p>
  <pre><code>readarray keys &lt;&lt;&lt; &quot;$(jq  '.&quot;Time Series (Daily)&quot; |  keys[]' newdata.json)&quot;
  for key in &quot;${keys[@]}&quot;; do
    jq -r --arg key &quot;$key&quot;  '. | .&quot;Time Series (Daily)&quot; | .[$key] | .&quot;1. open&quot;' newdata.json
  done
  </code></pre>