Skip to content

Instantly share code, notes, and snippets.

@pawel2105
Last active December 11, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawel2105/4662360 to your computer and use it in GitHub Desktop.
Save pawel2105/4662360 to your computer and use it in GitHub Desktop.
ActiveSupport::JSON.decode breaking when updating to Rails 2.3.16
@object = "{'source': 'Direct', 'details': 'Unknown', 'vdate': 1333236870729}"
Rails 3.2.15
> ActiveSupport::JSON.decode(@object)
# => {"details"=>"Unknown", "vdate"=>1333236870729, "source"=>"Direct"}
Rails 3.2.16
> ActiveSupport::JSON.decode(@object)
# => ActiveSupport::OkJson::Error: invalid character at "'source': 'D"
from /Users/schopenhauer/.rvm/gems/ruby-1.8.7-p370@contiki/gems/activesupport-2.3.16/lib/active_support/json/backends/okjson.rb:180:in `lex'
from /Users/schopenhauer/.rvm/gems/ruby-1.8.7-p370@contiki/gems/activesupport-2.3.16/lib/active_support/json/backends/okjson.rb:46:in `decode'
from /Users/schopenhauer/.rvm/gems/ruby-1.8.7-p370@contiki/gems/activesupport-2.3.16/lib/active_support/json/backends/okjson.rb:612:in `decode'
from /Users/schopenhauer/.rvm/gems/ruby-1.8.7-p370@contiki/gems/activesupport-2.3.16/lib/active_support/json/decoding.rb:14:in `__send__'
from /Users/schopenhauer/.rvm/gems/ruby-1.8.7-p370@contiki/gems/activesupport-2.3.16/lib/active_support/json/decoding.rb:14:in `decode'
@tagrudev
Copy link

[7] pry(main)> @object = "{"source": "Direct", "details": "Unknown", "vdate": 1333236870729}"
=> "{"source": "Direct", "details": "Unknown", "vdate": 1333236870729}"

[8] pry(main)> ActiveSupport::JSON.decode(@object)
=> {"source"=>"Direct", "details"=>"Unknown", "vdate"=>1333236870729}

@rdickey
Copy link

rdickey commented Jan 29, 2013

This happens in rails 3.0.20 as well. Apparently single-quotes no longer work, it will only accept double-quotes. Replacing single-quotes with double-quotes is not a viable solution; this was a minor release and should not introduce backwards incompatibilities.

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