title: Ruby getting deeply nested JSON API data
body: <p>I have a rails app which gets a response from World Weather Online API. I'm using the rest-client gem and the response is in JSON format.</p>
  
  <p>I parse the response using:</p>
  
  <pre><code>parsed_response = JSON.parse(response)
  </code></pre>
  
  <p>Where <code>parsed_response</code> is obviously a hash.</p>
  
  <p>The data I need are strings inside a hash inside an array inside a hash inside another array inside another hash inside another hash.</p>
  
  <p>The inner-most nested hashes are inside <code>["hourly"]</code>, an array of 8 hashes, each with 20 keys, possessing string values of various weather parameters. Each of these hashes in the array is a different time of day (the forecast is three-hourly, 3*8 = 24hours).</p>
  
  <p>So, for example, if I want the swell height in metres at 9pm, I find it with the following call:</p>
  
  <pre><code>@swell_height = parsed_data["data"]["weather"][0]["hourly"][7]["swellHeight_m"]
  </code></pre>
  
  <p>Where the 7th element in the array correspond to <code>"time" =&gt; "2100"</code></p>
  
  <p>While I can definitely work with this, I'm curious as to whether there is a more straightforward method of accessing my data, like if it was a database table, I could use active record, something like:</p>
  
  <pre><code>@swell_height = parsed_data.swellHeight_m.where(:time =&gt; "2100")
  </code></pre>