title: Extract JSON values from remote api with Ruby
body: <p>I'm trying to grab some data from last.fm and use it in a simple sinatra app. I've worked out how to open the document but having issues extracting the data in ruby here is the first list of the API data I'd like to grab the name:</p>
  
  <blockquote>
    <p>{"similarartists":{"artist":[{"name":"Sonny &amp; Cher"}]}</p>
  </blockquote>
  
  <p>This is just an extract of the return, I'm using this in my rb file:</p>
  
  <pre><code>require 'json'
  require 'open-uri'
  
  data = JSON.parse(open("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&amp;artist=editors&amp;api_key=xxx&amp;format=json").read)
  
  puts data["similarartists"]["artist"]["name"]
  </code></pre>
  
  <p>It doesn't seem to be working I get can't convert String into Integer (TypeError) on ruby 1.9.3 but the name in the JSON isn't an integer? If I just put the following:</p>
  
  <pre><code>puts data["similarartists"]["artist"]
  </code></pre>
  
  <p>It returns the whole thing, but I want to grab inside of that and get the name.</p>
  
  <pre><code>"name"=&gt;"Interpol"
  </code></pre>
  
  <p>I don't understand why it would complain about integers when the name is a string? Hope someone can help me!</p>