JSON.parse("a".to_json) fails! #84

Closed
shreyankg opened this Issue Aug 9, 2011 · 4 comments

Comments

Projects
None yet
4 participants

While according to the latest es5 standard (http://es5.github.com/#x15.12 ) "The top level JSONText production of the ECMAScript JSON grammar may consist of any JSONValue rather than being restricted to being a JSONObject or a JSONArray as specified by RFC 4627. " which could be a string.

Please fix this.

This highly affects also rails applications using redis as i18n backend, should be considered important!

Owner

flori commented Sep 19, 2011

You're misinterpreting what the ECMAScript standard says (maymust) and I don't see how it is relevant for JSON parsers that have to follow RFC 4627 and not the ECMAScript standard.

However, you can parse invalid JSON documents like these by setting the :quirks_mode option to true:

JSON.parse "a".to_json, :quirks_mode => true # => "a"

In this case auto-detecting encodings from octet streams won't work anymore.

flori closed this Sep 19, 2011

houen commented Sep 28, 2012

@flori it is quite relevant, as it seems to break rails I18n support for different backends. See: rails/rails#1499
yajl-ruby used to be the solution, but not on Rails 3.2

Owner

flori commented Sep 28, 2012

If it does cause problems, it would be possible to patch rails to parse JSON with the following option:

JSON.parse "a".to_json, :quirks_mode => true # => "a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment