title: How to parse a json response in rails
body: <p>First time working with JSON in Rails and trying to figure out something which seems like it should be quite basic.  I'm working w/ the Stripe Rails Library and trying to parse out and set one of the JSON elements to a variable.</p>
  
  <p>Here is my actual attempt:</p>
  
  <pre><code>    coupon = Stripe::Coupon.retrieve(self.discount_code)
      parsed_json = ActiveSupport::JSON.decode(coupon)
      discount_amount = parsed_json["percent_off"]
  </code></pre>
  
  <p>This line works:</p>
  
  <pre><code>coupon = Stripe::Coupon.retrieve("save50percent")
  </code></pre>
  
  <p>Running "puts coupon" in the console shows the JSON string</p>
  
  <p>JSON:  {"id":"test50","duration":"once","duration_in_months":null,"livemode":false,"max_redemptions":null,"object":"coupon","percent_off":50,"redeem_by":null,"times_redeemed":0} </p>
  
  <p>but trying to run:</p>
  
  <pre><code>parsed_json = ActiveSupport::JSON.decode(coupon)
  </code></pre>
  
  <p>results in the following error:</p>
  
  <pre><code>TypeError: can't convert Stripe::Coupon into String
  </code></pre>
  
  <p>I haven't even gotten to trying to parse out the value from the JSON - which i'm sure i've approached incorrectly.</p>
  
  <p>Thanks</p>