Skip to content

JSON.parse :symbolize_names => true does not work in every case #70

isuda opened this Issue Apr 6, 2011 · 1 comment

3 participants

isuda commented Apr 6, 2011

If you try to parse this json with :symbolize_names, the parser will throw an "interning empty string" exception when trying to convert the empty string to a symbol.

{"":"this is weird","state":"success"}

I'm not sure if there is any good way to "fix" this problem, or if it needs fixing. You could argue that if you could get JSON in that format you shouldn't be using :symbolize_names. I just thought I would report it.

I like using the :symbolize_names option, but it sucks that it will fail in this specific way on valid json. (even if that json is weird...)

mernen commented Apr 7, 2011

Yes, I don't think we can really work around that, as mangling the data wouldn't be an acceptable option IMO. Perhaps the best solution is to mention it in the documentation so that people are more aware of this limitation? Same thing applies to nulls: :"\0" will fail on Ruby 1.8, just like JSON.parse('{"foo\u0000": "bar"}', :symbolize_names=>true).

Both restrictions are lifted on Ruby 1.9, by the way. I can't remember any other symbol name restrictions right now.

@flori flori closed this Feb 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.