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 are not double quoted:>> {1 => 2}.to_json=> "{1: 2}" Is this intentional or a bug? If all keys were double quoted this would become:>> {1 => 2}.to_json=> "{\"1\": 2}" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Jan 13, 2009 at 01:20, nootch <noah.box@gmail.com> wrote:> > Is this intentional or a bug? If all keys were double quoted this > would become: > > >> {1 => 2}.to_json > => "{\"1\": 2}"It is a bug. JSON doesn''t allow data types for keys other than strings. It also dictates, as you''ve noticed, double quote marks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Ok. Added a patch for this: http://github.com/weplay/rails/commit/b73fc178190a98a60d3e4e896e73c9380d7aeea1 On Jan 12, 8:10 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com> wrote:> On Tue, Jan 13, 2009 at 01:20, nootch <noah....@gmail.com> wrote: > > > Is this intentional or a bug? If all keys were double quoted this > > would become: > > > >> {1 => 2}.to_json > > => "{\"1\": 2}" > > It is a bug. JSON doesn''t allow data types for keys other than strings. It > also dictates, as you''ve noticed, double quote marks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I''ve actually gone ahead and submitted this as a proper patch/ticket to lighthouse. http://rails.lighthouseapp.com/projects/8994/tickets/1755-json-encoding-of-hashes-does-not-always-properly-double-quote-keys If anyone has a second to verify this, would be great. Thanks - Noah On Jan 12, 9:22 pm, nootch <noah....@gmail.com> wrote:> Ok. Added a patch for this: > > http://github.com/weplay/rails/commit/b73fc178190a98a60d3e4e896e73c93... > > On Jan 12, 8:10 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com> > wrote: > > > On Tue, Jan 13, 2009 at 01:20, nootch <noah....@gmail.com> wrote: > > > > Is this intentional or a bug? If all keys were double quoted this > > > would become: > > > > >> {1 => 2}.to_json > > > => "{\"1\": 2}" > > > It is a bug.JSONdoesn''t allow data types for keys other than strings. It > > also dictates, as you''ve noticed, double quote marks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---