title: JSON response from Google Analytics api
body: <p>I am using the google-api-ruby-client to get a response from the Google Analytics api, which is successful, the one thing I am a little confused with though is the response object. I would like to know how to drill down into specific keys and their values or even parse the response to make it more understandable.</p>
  
  <p>Below is what I believe is the relevant part of the JSON response</p>
  
  <pre><code>"{\"kind\":\"analytics#gaData\",\"id\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:88893966&amp;dimensions=ga:pagePath&amp;metrics=ga:pageviews&amp;filters=ga:pagePath%3D%3D/&amp;start-date=2014-01-01&amp;end-date=2014-07-22\",\"query\":{\"start-date\":\"2014-01-01\",\"end-date\":\"2014-07-22\",\"ids\":\"ga:88893966\",\"dimensions\":\"ga:pagePath\",\"metrics\":[\"ga:pageviews\"],\"filters\":\"ga:pagePath==/\",\"start-index\":1,\"max-results\":1000},\"itemsPerPage\":1000,\"totalResults\":1,\"selfLink\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:88893966&amp;dimensions=ga:pagePath&amp;metrics=ga:pageviews&amp;filters=ga:pagePath%3D%3D/&amp;start-date=2014-01-01&amp;end-date=2014-07-22\",\"profileInfo\":{\"profileId\":\"88893966\",\"accountId\":\"53082810\",\"webPropertyId\":\"UA-53082810-1\",\"internalWebPropertyId\":\"85713348\",\"profileName\":\"All Web Site Data\",\"tableId\":\"ga:88893966\"},\"containsSampledData\":false,\"columnHeaders\":[{\"name\":\"ga:pagePath\",\"columnType\":\"DIMENSION\",\"dataType\":\"STRING\"},{\"name\":\"ga:pageviews\",\"columnType\":\"METRIC\",\"dataType\":\"INTEGER\"}],\"totalsForAllResults\":{\"ga:pageviews\":\"8\"},\"rows\":[[\"/\",\"8\"]]}"
  </code></pre>
  
  <p>which is obtained from</p>
  
  <pre><code># make queries
  result = client.execute(:api_method =&gt; api_method, :parameters =&gt; {
    'ids'        =&gt; PROFILE,
    'start-date' =&gt; Date.new(2014,1,1).to_s,
    'end-date'   =&gt; Date.today.to_s,
    'dimensions' =&gt; 'ga:pagePath',
    'metrics'    =&gt; 'ga:pageviews',
    'filters'    =&gt; 'ga:pagePath==/'
   })
  
   puts ap(result)
  </code></pre>
  
  <p>Also when I do:</p>
  
  <pre><code>puts ap(result.data.rows.inspect)
  #returns
  "[[\"/\", \"8\"]]"
  </code></pre>
  
  <p>and when i try</p>
  
  <pre><code>response = JSON.parse(result.data.totalsForAllResults)
  puts ap(response)
  # returns error
  TypeError: no implicit conversion of #&lt;Class:0x00000001950550&gt; into String
  </code></pre>
  
  <p>I am wondering how I can format the response without the backslashes and how I would say get the total page views?</p>