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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:49:01+00:00 2026-05-18T01:49:01+00:00

I have spent days on this trying out all the JSON libraries including the

  • 0

I have spent days on this trying out all the JSON libraries including the JSON gem, Yajl-ruby, ActiveSupport::JSON and nothing can do this simple task:

user = User.find(1)
json = user.to_json
user2 = json.as_json # OR json.from_json 
                     # OR JSON.parse(json) 
                     # OR Yajl::Parser.parse(json)
                     # OR ActiveSupport::JSON.decode(json)

When I try to use the deserialized JSON data to create a new User, I get one of the following errors:

User.new(Yajl::Parser.parse(json))  
# ActiveRecord::UnknownAttributeError: unknown attribute: json_class

User.new(json.as_json)
# NoMethodError: undefined method `stringify_keys!' for #<String:0xb6de4318>

User.new(JSON.parse(json))
# NoMethodError: undefined method `stringify_keys!' for #<User:0xb6dc7470>

User.new(ActiveSupport::JSON.decode(json))
# NoMethodError: undefined method `stringify_keys!' for #<User:0xb6da3764>

This is so easy to do with YAML using to_yaml and from_yaml. Why can’t to_json produce the kind of JSON that from_json could convert back to a ruby object?

Edit: I am using Rails 2.3.8, although I have tried 2.3.5 and 3.0.0. Also, I am using the json-rpc plugin to create a JSON-RPC service, although the same problem persists without the plugin.

  • 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-18T01:49:02+00:00Added an answer on May 18, 2026 at 1:49 am
    json = Episode.first.to_json
    dec = ActiveSupport::JSON.decode json
    Episode.new dec['episode']
    

    Works for me in Rails 3.0.1. In your examples you didn’t take out actual attributes dict from wrapper dict after you converted JSON back to Ruby. You should try

    User.new(ActiveSupport::JSON.decode(json)['user'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent a few days trying to figure this one out and can't seem
Ok so I've spent a couple hours trying to resolve this issue and have
Alright I've spent a good three days trying this, here's the scenario: I want
I've spent a couple of days trying to find out what's going on. I
I have spent several hours trying to find a means of writing a cross
I have spent too much time on this problem and am beginning to think
I've spent two days on this and I still can't find the cause of
This case is really strange, i've spent 2 whole days to get Twitter Oauth
I realize that this is probably a very basic question, but I have spent
I have spent lot of time doing research on VIM. I am Windows guy

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.