title: Accessing hashes and arrays Ruby
body: <p>In my Rails application I'm sending a complex JSON string that needs to get decoded. That's not the problem I know how.</p>
  
  <p>Now before I implement everything I'm trying to access some example JSON structures to see if I can get to all the variables. The problem is that the names can be variable.</p>
  
  <pre><code>{"configurations" : [ 
  { "drinks" : [
          {"menus" : [
            { "hot" : [
              {"id":15,"unit":"0.33", "price":"1", "currency":"Euro", "position": 4},
              {"id":15,"unit":"0.33", "price":"1", "currency":"Euro", "position": 6}
            ] },
  
            { "cold" : [
          {"id":15,"unit":"0.33", "price":"1", "currency":"Euro", "position": 4},
              {"id":15,"unit":"0.33", "price":"1", "currency":"Euro", "position": 6}
             ] },
  
            { "terminals" : [ {"id" : 4}, {"id": 6}, {"id": 7} ] }, 
  
            { "keys" : { "debit" : "on", "credit": "off" }  }
  
          ] }
  ] } ] } 
  </code></pre>
  
  <p>Ok, now the following fields <strong>are variable</strong>: <strong>"drinks", "hot", "cold"</strong>. All the other fields will be called the same.</p>
  
  <p>Now I would like to access every variable in this JSON string after I decoded it. Before implementing it, I tryed a simple JSON:</p>
  
  <pre><code>{"configuration" : [ { "drinks" : [ { "id":15, "unit":"0.33" } ] } ] }
  </code></pre>
  
  <p>After decoding in rails resulting in</p>
  
  <pre><code>{ "configuration" =&gt; [{"drinks" =&gt; [{"id" =&gt; 15, "unit" =&gt; "0.33" }]}]}
  </code></pre>
  
  <p>Now how can I access for example <code>id</code> and <code>unit</code> without using the word "drinks". The solution should also be scalable to the example above.</p>
  
  <p>Some extra information: In the large JSON I should access all the items listed there (the id's) save them to a table and return the new id and then insert it back in the JSON. (explaining why this needs to be done will take an extra page or 4 ^^ ).</p>