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

  • Home
  • SEARCH
  • 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 182213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:54:01+00:00 2026-05-11T14:54:01+00:00

I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and

  • 0

I am stumped with this problem.

ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same — the ActiveSupport version takes arguments and the JSON gem version doesn’t.

I installed a gem that required the JSON gem and my app broke. The issue is that I’m using to_json in a controller that returns a list of objects, but I want to control which attributes are returned.

When code anywhere in my system does require 'json' I get this error message:

TypeError: wrong argument type Hash (expected Data)

I tried a couple of things that I read online to fix it, but nothing worked. I ended up re-writing the gem to use ActiveSupport::JSON.decode instead of JSON.parse.

This works but it’s not sustainable…I can’t be forking gems every time I want to use a gem that requires the JSON gem.

Update: The best solution of this problem is to upgrade to Rails 2.3 or higher, which fixed it.

  • 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. 2026-05-11T14:54:01+00:00Added an answer on May 11, 2026 at 2:54 pm

    Update This fix is only applicable to Rails < 2.3. As Giles mentions below, they fixed this in 2.3 internally using much the same technique. But beware the json gem’s earlier attempt at Rails compatibility (json/add/rails), which, if required explicitly will break everything all over again.

    Do you mean the require 'json' statement itself raises that Exception? Or do you mean when you call @something.to_json(:something => value) you get the error? The latter is what I would expect, if you have a problem requiring the JSON gem then I’m not sure what’s going on.

    I just ran into this problem with the oauth gem. In my case, there is not a true conflict, because the oauth gem doesn’t depend on to_json implementation. Therefore the problem is that JSON is clobbering the ActiveSupport declarations. I solved this by simply requiring json before ActiveSupport is loaded. Putting

    require 'json' 

    inside the Rails::Initializer did the trick (though putting it after the block did NOT).

    That allows ActiveSupport to clobber the default JSON implementation instead.

    Now if you are using a gem that actually depends on the JSON implementation of to_json then you are up a creek. This is definitely the worst of meta-programming, and I would advocate for the Rails and JSON gem developers to resolve the conflict, though it will be painful because one or the other will have to break backwards compatibility.

    In the short term, gem authors may be able to bridge the gap by supporting both implementations. This is more or less feasible depending on how the gem uses the method. A worst case scenario is an official fork (ie. gem and gem-rails).

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

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using Windows Script: Set ComputerObj = GetObject("WinNT://MYCOMPUTER") ComputerObj.Filter = Array("Service")… May 11, 2026 at 5:12 pm
  • Editorial Team
    Editorial Team added an answer If it were me, I'd be keeping my config values… May 11, 2026 at 5:12 pm
  • Editorial Team
    Editorial Team added an answer Two articles on the .NET memory model (which is stronger… May 11, 2026 at 5:12 pm

Related Questions

I have a fairly simple CRUD web application (C#/ASP.NET) that runs fine in Firefox,
I am completely stumped. I have a program that pulls information stored in a
Here is my sample code. It is meant to be an iterative procedure for
I am having an issue with SSH hanging on my Mac Book Pro. This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.