title: Ruby to_json on objects wrapped in quote's
body: <p>I'm trying to create a super easy JSON webservice for a side-project. However I'm having some trouble converting my objects to JSON, could someone please help me out ?</p>
  
  <p>I have the following classes: </p>
  
  <pre><code>class Location
    attr_reader :street, :city, :state, :country, :zip, :latitude, :longitude
  
    def initialize(street, city, state, country, zip, latitude, longitude)
      @street = street
      @city = city
      @state = state
      @country = country
      @zip = zip
      @latitude = latitude
      @longitude = longitude
    end
  
    def to_json
      {
        'street' =&gt; @street,
        'city' =&gt; @city,
        'state' =&gt; @state,
        'country' =&gt; @country,
        'zip' =&gt; @zip,
        'latitude' =&gt; Float(@latitude),
        'longitude' =&gt; Float(@longitude)
      }.to_json
    end
  end
  </code></pre>
  
  <p>and </p>
  
  <pre><code>class Spot
    attr_reader :name, :category, :location, :id
  
    def initialize(id, name, category, location)
      @name = name
      @category = category
      @location = location
      @id = id
    end
  
    def to_json
      {
        'name' =&gt; @name,
        'category' =&gt; @category,
        'location' =&gt; @location.to_json,
        'id' =&gt; @id
      }.to_json
    end
  
  end
  </code></pre>
  
  <p>Given a random input I would like the output to be something like this:</p>
  
  <pre><code>{
  "name":"Wirelab",
  "category":"Bier",
  "location":
  {
      "street":"Blaatstraat 12",
      "city":"Enschede",
      "state":"Overijssel",
      "country":"Nederland",
      "zip":"7542AB",
      "latitude": 31.21312,
      "longitude":41.1209
  }
  ,
  "id":"12"
  }
  </code></pre>
  
  <p>However the ouput I'll get is this:</p>
  
  <pre><code>{
      "name":"Wirelab",
      "category":"Bier",
      "location":"
      {
          "street\":"Blaatstraat 12",
          "city\":\"Enschede\",
          \"state\":\"Overijssel\",
          \"country\":\"Nederland\",
          \"zip\":\"7542AB\",
          \"latitude\":31.21312,
          \"longitude\":41.1209
      }
      ",
      "id":"12"
  }
  </code></pre>
  
  <p>Could someone please explain me how I can fix this ?</p>
  
  <p>EDIT:</p>
  
  <p>I'm using a Sintra webservice which looks something like this:</p>
  
  <pre><code>get '/spots' do  
         #json = spots.to_json
         spot =  Spot.new("12", "Wirelab", "Bier", Location.new("Blaatstraat 12", "Enschede", "Overijssel", "Nederland", "7542AB", "31.21312", "41.1209"))
         json = spot.to_json
         if callback
           content_type :js
           response = "#{callback}(#{json})" 
        else
           content_type :json
           response = json
         end
    response
  end
  </code></pre>