Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8117203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:05:16+00:00 2026-06-06T04:05:16+00:00

First time working with JSON in Rails and trying to figure out something which

  • 0

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.

Here is my actual attempt:

    coupon = Stripe::Coupon.retrieve(self.discount_code)
    parsed_json = ActiveSupport::JSON.decode(coupon)
    discount_amount = parsed_json["percent_off"]

This line works:

coupon = Stripe::Coupon.retrieve("save50percent")

Running “puts coupon” in the console shows the JSON string

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}

but trying to run:

parsed_json = ActiveSupport::JSON.decode(coupon)

results in the following error:

TypeError: can't convert Stripe::Coupon into String

I haven’t even gotten to trying to parse out the value from the JSON – which i’m sure i’ve approached incorrectly.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:05:18+00:00Added an answer on June 6, 2026 at 4:05 am

    Your error message says it all: coupon is a Stripe::Coupon, not a String. Try using the available to_json method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time working with Quartz. I am trying out a sample
I am working on an offline-mode iPhone application in which the first time data
This is my first time attempting working with JQuery, Json AND calling a web
This is my first time working with localStorage, and I'm trying to store a
I am working with JSON parsing for the first time on Iphone. I need
First time working with javascript and JSON. Curious why this causes a comiler error:
This is my first time working with regular expressions and I've been trying to
I am working on a backbone.js application with rails api which provides the json
I'm working with JSON data for the first time and I've got some PHP
This is my first time working with a JSON and I am clearly getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.