Accept :symbolize_names in JSON gem compat mode #94

niko opened this Issue Dec 28, 2011 · 8 comments


None yet

8 participants


yajl-ruby claims to be compatible with the JSON gem when requiring 'yajl/json_gem'. When parsing it should accept the same options whenever possible. At least :symbolize_keys should be interpreted as :symbolize_names. This is suboptimal IMHO:

string = '{"bla": "blub"}'

require 'json'
JSON.parse string, :symbolize_names => true # => {:bla=>"blub"}
JSON.parse string, :symbolize_keys => true  # => {"bla"=>"blub"}

require 'yajl/json_gem'
JSON.parse string, :symbolize_names => true # => {"bla"=>"blub"}
JSON.parse string, :symbolize_keys => true  # => {:bla=>"blub"}
@srushti srushti added a commit to c42engineering/yajl-ruby that referenced this issue Jul 30, 2012
@srushti srushti allowing symbolize_names to be used instead of symbolize_keys for com…
…patibility with the json gem. #94

Here's a sort of trivial solution implementing the symbolize_names compatibility. With this patch, if either of those two is true Yajl will return symbols. If they have opposite values, it'll still symbolize the keys.



just spent about an hour tracking this down in some complex logic.


I find it disturbing that this wasn't mandatory from the moment someone decided to make this the default JSON parser in rails.


@heldersilva for what it's worth the JSON gem added the :symbolize_names option after yajl-ruby already had :symbolize_keys (in other words they added a feature that previously only existed in yajl-ruby). I just never went back and added the backward compatibility in.

Thankfully someone else got around to it in #105 which has since been merged. Forgot this issue was still open :)

@brianmario brianmario closed this Jan 28, 2013


Sorry for the tad bitter comment, but I took 2 hours to figure this out and I was a bit mad.
Again, sorry, I will try to relax before I post.

And thanks for yajl =)


Sorry to bump an old thread, but is there any chance this can be back ported to a v1.1.1 gem release?

I just hit this issue because:

  • we are using the multi_json gem
  • we are using the yajl-ruby gem
  • when multi_json uses the JsonGem adapter, we hit this issue, because multi_json thinks ::JSON.parse expects :symbolize_names

If not, that's ok - I can always make a fork. :)

@martijn martijn pushed a commit to bluerail/money that referenced this issue Sep 26, 2016
Dave Kroondyk Fix for symbolizing currency hash keys when yajl-ruby is used for JSON.
The json and yajl gems are not 100% compatible in terms of API. One
main difference is on JSON.parse, the standard json gem takes a
:symbolize_names option while yajl takes :symbolize_keys. There already
is a ticket on the yajl ruby gem to make it play nice with the json gem:


Luckily, both params can be passed to either gem and have it function
as desired. Discovered this here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment