This project is archived and is in readonly mode.
JSON encoding of hashes does not always properly double quote keys
Reported by Noah | January 14th, 2009 @ 02:06 AM | in 2.x
I noticed that as of rails 2.x all hash keys were intended to be double quoted in JSON encodings. Indeed there's an ActiveSupport test method called "test_hash_key_identifiers_are_always_quoted". I noticed however that this isn't actually the case -- numeric keys for example are not double quoted:
{1 => 2}.to_json
=> "{1: 2}"
The proper JSON encoding would encode this numeric key as a doubly quoted string as follows:
{1 => 2}.to_json
=> "{"1": 2}"
I've attached a patch which address this problem by checking to see if the hash key is properly quoted - if it's not, it adds double quotes to the hash key.
Comments and changes to this ticket
-
Michael Koziarski January 15th, 2009 @ 08:43 PM
- Assigned user set to Michael Koziarski
Is there any reason we couldn't do this instead?
-
Repository January 16th, 2009 @ 04:40 AM
- State changed from new to committed
(from [0bed5bdb213ea68e2f167ac4f61f698f37cf2d69]) Properly quote json keys.
According to the RFC and the json.org site all json keys must be strings, and those strings must be quoted with double quotes. [#1755 state:committed] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1755 JSON encoding of hashes does not always properly double quote keys According to the RFC and the json.org site all json keys ...