title: Creating a new instance/object from a class with nested JSON key value pairs in Ruby
body: <p>I have some JSON that I want to convert to an object but I'm having trouble figuring out how to sort the data and pass it into an initialize method for a class.</p>
  <p>I've already used file.read to put my JSON into key/value pairs organised within an array, however the cost attribute is nested as follows</p>
  <pre><code>      [
          { &quot;restaurant&quot;: &quot;hells kitchen&quot;, &quot;cost&quot;: { &quot;dine in&quot;: 100.00 } },
          { &quot;restaurant&quot;: &quot;sals pizza&quot;, &quot;cost&quot;: { &quot;dine in&quot;: 25.50, &quot;takeaway&quot;: 20.00, &quot;delivery&quot;: 28.50 } },
          { &quot;restaurant&quot;: &quot;five guys burgers&quot;, &quot;cost&quot;: { &quot;dine in&quot;: 18.50, &quot;takeaway&quot;: 16.50, &quot;delivery&quot;: 20.00 } }
        ]
  </code></pre>
  <p>Ideally I'd like to assign these values and have them accessible as attributes of the instantiated class object like this a rough example.</p>
  <pre><code>class Restaurant
  
      attr_accessor :name, :type, :cost
  
      def initialise(json_data)
      
      #something to sort the data here#
      
      end
  
  end 
  </code></pre>
  <p>I can't figure out a good way of adding the data to the attributes and would really appreciate any advice on how to retrieve the data and place it into the initialize method.</p>
  <p>My apologies in advance if my terminology, explanation or understanding is lacking, I'm very new to Ruby and programming in general.</p>
  <p>Thank you!</p>