Please check out this ticket (which would explain almost everything): http://dev.rubyonrails.org/ticket/8762 So basically, Rails to_json methods produces invalid JSON out of the box as it doesn''t quote all hash keys. This is valid JSON: { "id": 6589, "code": "SIN", "name": "Singapore" } This is not (Rails'' JSON encoders do this): { id: 6589, code: "SIN", name: "Singapore" } I''m sure many of us would like to see Rails start producing valid JSON by default instead of having to change a module attribute. I think it''s absolutely important that Rails outputs valid JSON by default. Would definitely be imperative prior to the Rails 2.0 release, especially with the attempt to achieve feature parity between XML and JSON for encoding, decoding and serialization (see changesets http://dev.rubyonrails.org/changeset/7519 and http://dev.rubyonrails.org/changeset/7518). If there''s a historical reason for it, can someone shed some light? Worst case is that Rails 2.0 goes out with a big fat JSON warning about the invalid JSON by default ;) Oh and the easiest solution: set ActiveSupport::JSON.unquote_hash_key_identifiers = false by default in ActiveSupport::JSON (http://dev.rubyonrails.org/browser/ trunk/activesupport/lib/active_support/json/encoding.rb). Cheers, Chu Yeow --~--~---------~--~----~------------~-------~--~----~ 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 support this +1 On Sep 27, 7:51 pm, chuyeow <chuy...@gmail.com> wrote:> Please check out this ticket (which would explain almost everything):http://dev.rubyonrails.org/ticket/8762 > > So basically, Rails to_json methods produces invalid JSON out of the > box as it doesn''t quote all hash keys. This is valid JSON: > > { > "id": 6589, > "code": "SIN", > "name": "Singapore" > > } > > This is not (Rails'' JSON encoders do this): > > { > id: 6589, > code: "SIN", > name: "Singapore" > > } > > I''m sure many of us would like to see Rails start producing valid JSON > by default instead of having to change a module attribute. I think > it''s absolutely important that Rails outputs valid JSON by default. > Would definitely be imperative prior to the Rails 2.0 release, > especially with the attempt to achieve feature parity between XML and > JSON for encoding, decoding and serialization (see changesetshttp://dev.rubyonrails.org/changeset/7519andhttp://dev.rubyonrails.org/changeset/7518). > > If there''s a historical reason for it, can someone shed some light? > Worst case is that Rails 2.0 goes out with a big fat JSON warning > about the invalid JSON by default ;) > > Oh and the easiest solution: set > ActiveSupport::JSON.unquote_hash_key_identifiers = false > by default in ActiveSupport::JSON (http://dev.rubyonrails.org/browser/ > trunk/activesupport/lib/active_support/json/encoding.rb). > > Cheers, > Chu Yeow--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey eggie, You''d be glad to know that this has been fixed! :) Edge Rails (and Rails 2.0) will emit valid JSON by default now. Cheers, Chu Yeow On Oct 4, 11:08 am, eggie5 <egg...@gmail.com> wrote:> I support this +1 > > On Sep 27, 7:51 pm, chuyeow <chuy...@gmail.com> wrote: > > > Please check out this ticket (which would explain almost everything):http://dev.rubyonrails.org/ticket/8762 > > > So basically, Rails to_json methods produces invalid JSON out of the > > box as it doesn''t quote all hash keys. This is valid JSON: > > > { > > "id": 6589, > > "code": "SIN", > > "name": "Singapore" > > > } > > > This is not (Rails'' JSON encoders do this): > > > { > > id: 6589, > > code: "SIN", > > name: "Singapore" > > > } > > > I''m sure many of us would like to see Rails start producing valid JSON > > by default instead of having to change a module attribute. I think > > it''s absolutely important that Rails outputs valid JSON by default. > > Would definitely be imperative prior to the Rails 2.0 release, > > especially with the attempt to achieve feature parity between XML and > > JSON for encoding, decoding and serialization (see changesetshttp://dev.rubyonrails.org/changeset/7519andhttp://dev.rubyonrails.or...). > > > If there''s a historical reason for it, can someone shed some light? > > Worst case is that Rails 2.0 goes out with a big fat JSON warning > > about the invalid JSON by default ;) > > > Oh and the easiest solution: set > > ActiveSupport::JSON.unquote_hash_key_identifiers = false > > by default in ActiveSupport::JSON (http://dev.rubyonrails.org/browser/ > > trunk/activesupport/lib/active_support/json/encoding.rb). > > > Cheers, > > Chu Yeow--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- 2 more JSON / XML feature parity patches before Rails 2.0
- Merb-style development exception pages for Mac OS X
- [ActiveSupport] Patches needing review: re-organization of #to_query methods, preservation of XML/JSON content-type
- [PATCH] x 2 - Fix for "null pointer exception" when ask_status is called before worker is run, and docfixes
- Trac not for general use?