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 3314428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:13:54+00:00 2026-05-17T22:13:54+00:00

My to_json call sometimes seems to include some extra cruft that I’m not expecting:

  • 0

My to_json call sometimes seems to include some extra cruft that I’m not expecting:

{"response":
  [{"attributes":
    {
        (...actual list of key:value pairs, as expected)
    },
    "json_class":"Survey",
    "attributes_cache":{}
   },
   {"changed_attributes":{"survey_source":""},
    "attributes":
    {
     (...actual list of key:value pairs, as expected)
    },
    "json_class":"Survey",
    "attributes_cache":{}}
  ],
  "status_code":"200","status_description":"OK"}

What I’m expecting is closer to this:

{"response":
  [survey: {
     (...list of key:value pairs...)
   }, 
   survey: {
     (...list of key:value pairs...)
    }
  ],
  "status_code":"200","status_description":"OK"}

As far as I can tell, the extra stuff that shows up is used by AR to keep track of the state of dirty objects, but I’m not sure why it gets picked up by to_json. My code does nothing fancy as far as I can tell:

RESPONSE_OK = {"status_code" => "200", "status_description" => "OK"}
@surveys = Survey.find_all_by_state("RUNNING")
response = RESPONSE_OK.merge({"response" => @surveys})
respond_to do |format|
    format.json {
        render :json => response.to_json(:methods => :intercept, :include => {:question_groups => {:include => [:questions]}})
    }
end

I cannot reproduce it on the Rails console (including a simpler example for legibility, but I get the same result for my actual code):

  ?> s = Survey.find_by_id(49)
  => #<Survey id: 49, name: "Cat?", description: "", created_at: "2010-08-29 17:50:45", updated_at: "2010-08-29 17:50:45", order: nil, entrance_logic: nil, user_id: 187, state: "RUNNING", maxresponses: 0, isrepeatable: false, reward_description: nil, compensation_amount: 0, survey_source: nil, responses_received: nil, is_profile_survey: false, hash_id: "123", survey_alias: "456", prerequisites: nil, is_web_survey: false, max_invites: 0, is_social: true>
  >> s.to_json
  => "{"survey":{"survey_source":null,"prerequisites":null,"name":"Cat?","isrepeatable":false,"maxresponses":0,"hash_id":"123","entrance_logic":null,"created_at":"2010-08-29T17:50:45Z","survey_alias":"456","updated_at":"2010-08-29T17:50:45Z","reward_description":null,"responses_received":null,"order":null,"id":49,"user_id":187,"max_invites":0,"is_web_survey":false,"is_social":true,"is_profile_survey":false,"description":"","compensation_amount":0,"state":"RUNNING"}}"
  >> s.reward_description = "100 points"
  => "100 points"
  >> s.to_json
  => "{"survey":{"survey_source":null,"prerequisites":null,"name":"Cat?","isrepeatable":false,"maxresponses":0,"hash_id":"123","entrance_logic":null,"created_at":"2010-08-29T17:50:45Z","survey_alias":"456","updated_at":"2010-08-29T17:50:45Z","reward_description":"100 points","responses_received":null,"order":null,"id":49,"user_id":187,"max_invites":0,"is_web_survey":false,"is_social":true,"is_profile_survey":false,"description":"","compensation_amount":0,"state":"RUNNING"}}"
  >> s.changed
  => ["reward_description"]
  >> s.changed_attributes
  NoMethodError: Attempt to call private method
          from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:236:in `method_missing'
          from (irb):45
          from :0
  >>

Thanks for any insights! I’m sure I can modify my code to find a workaround (if all else fails I can just build the hash I pass to to_json by hand), but I would like to gain some understanding of why this happens, if possible.

  • 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-05-17T22:13:54+00:00Added an answer on May 17, 2026 at 10:13 pm

    I just had the same problem – and solved it after extensive googling.

    You have a JSON gem installed (perhaps as a dependency of another gem) and this is determining your to_json output.

    Remove the gem (if you can) and it’ll come good.

    🙂

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

Sidebar

Related Questions

I have a webmethod that returns a Hashtable through a jQuery ajax call along
I'm making AJAX calls to a server that sometimes return unparseable JSON. The server
Im calling a WCF service from jquery ajax. Sometimes the service throw some custom
I am trying a straightforward remote json call with jquery. I am trying to
I am looking for an enhancement to JSON that will also serialize methods. I
I'm writing an RSS to JSON parser and as a part of that, I
I am getting a response from ajax request(done by jquery). I have a method
On my website I use a long polling jquery ajax function. This ajax call
I have a simple call JSON.parse(Panda.get(/videos/#{self.panda_video_id}/encodings.json)) Which returns : can't convert Array into String
I have a text file that is formatted like JSON, but in a print/view

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.