Hi guys, Hoping to learn something here. (folks at #8762<http://dev.rubyonrails.org/ticket/8762>would be interested as well) Currently Hash#to_json produces text with unquoted keys, which is invalid JSON. Asking developers to set ActiveSupport:: JSON.unquote_hash_key_identifiers to false if they want valid JSON doesn''t seem in character of Rails, i.e. "smart defaults"... or is valid JSON the rarer requirement in common cases? This doesn''t appear to be a bug nor an accident. In fact, thought and effort has gone into making to_json to consistently produce invalid JSON: [5486<http://dev.rubyonrails.org/changeset/5486#file2>], [6443 <http://dev.rubyonrails.org/changeset/6443#file5>]. i.e. [6443] fights away ticket #7714 <http://dev.rubyonrails.org/ticket/7714> by bringing in an elaborate ActiveSupport::JSON::RESERVED_WORDS instead of *returning* to produce valid JSON (as requested in ticket). Hope somebody could shed some light on this design decision and I''ll learn some Ruby. Cheers -- choonkeat --~--~---------~--~----~------------~-------~--~----~ 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 9/17/07, choonkeat <choonkeat@gmail.com> wrote:> > > Currently Hash#to_json produces text with unquoted keys, which is invalid > JSON. Asking developers to set ActiveSupport:: > JSON.unquote_hash_key_identifiers to false if they want valid JSON doesn''t > seem in character of Rails, i.e. "smart defaults"... or is valid JSON the > rarer requirement in common cases?Didn''t even know Rails did that. Since #to_json produces valid JavaScript, obviously we that are using JSON from Rails didn''t realize that in fact it isn''t valid JSON. There isn''t any explanation to unquote the hash keys except to save a few bytes, which is hardly worth invalidating the spec. After all, JSON data is used in far more places than just eval() in JavaScript. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
aloha, From schema_statements.rb: def options_include_default?(options) options.include?(:default) && !(options[:null] == false && options[:default].nil?) end Isn''t that the same as simply: def options_include_default?(options) options.include?(:default) end ? lawrence --~--~---------~--~----~------------~-------~--~----~ 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 9/17/07, lawrence <lawrence.pit@gmail.com> wrote:> > > From schema_statements.rb: > > options.include?(:default) && !(options[:null] == false && > options[:default].nil?) > > Isn''t that the same as simply: > > options.include?(:default) >No. The first one checks if the options[:default] is not nil when options[:null] is false. The second only checks for the presence of :default as key, which is far from equivalent. --~--~---------~--~----~------------~-------~--~----~ 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 want to know why too, and I think we should get an answer soon considering how DHH seems to want to achieve feature parity between JSON and XML for Rails 2.0 (you can, for example, use ARes while speaking JSON and AR objects now convert nicely to JSON). I agree it just doesn''t make much sense to me either to have invalid JSON emitted by default. Cheers, Chu Yeow Mislav Marohni�? wrote:> On 9/17/07, choonkeat <choonkeat@gmail.com> wrote: >> >> >> Currently Hash#to_json produces text with unquoted keys, which is invalid >> JSON. Asking developers to set ActiveSupport:: >> JSON.unquote_hash_key_identifiers to false if they want valid JSON doesn''t >> seem in character of Rails, i.e. "smart defaults"... or is valid JSON the >> rarer requirement in common cases? > > > Didn''t even know Rails did that. Since #to_json produces valid > JavaScript, > obviously we that are using JSON from Rails didn''t realize that in fact > it > isn''t valid JSON. > > There isn''t any explanation to unquote the hash keys except to save a > few > bytes, which is hardly worth invalidating the spec. After all, JSON data > is > used in far more places than just eval() in JavaScript.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Currently Hash#to_json produces text with unquoted keys, which is invalid > JSON. Asking developers to set ActiveSupport:: > JSON.unquote_hash_key_identifiers to false if they want > valid JSON doesn''t seem in character of Rails, i.e. "smart defaults"... or > is valid JSON the rarer requirement in common cases?I''ve dug around the history and asked a few folks an it seems there''s no particularly valid reason for us to continue to support the current behaviour. Send in a patch which switches the default and perhaps removes the option, and I''ll see it gets applied. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ 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 9/28/07, Michael Koziarski <michael@koziarski.com> wrote:> > > I''ve dug around the history and asked a few folks an it seems there''s > no particularly valid reason for us to continue to support the current > behaviour. Send in a patch which switches the default and perhaps > removes the option, and I''ll see it gets applied.Maybe the option should stay but have no effect and should trigger a deprecation warning? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome. Thanks for digging around! I''ve submitted a patch here: http://dev.rubyonrails.org/ticket/8762 (please ignore the first patch, that''s the wrong file). Please take a look. Cheers, Chu Yeow Michael Koziarski wrote:>> Currently Hash#to_json produces text with unquoted keys, which is invalid >> JSON. Asking developers to set ActiveSupport:: >> JSON.unquote_hash_key_identifiers to false if they want >> valid JSON doesn''t seem in character of Rails, i.e. "smart defaults"... or >> is valid JSON the rarer requirement in common cases? > > I''ve dug around the history and asked a few folks an it seems there''s > no particularly valid reason for us to continue to support the current > behaviour. Send in a patch which switches the default and perhaps > removes the option, and I''ll see it gets applied. > > -- > Cheers > > Koz-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
+1 and patching test in actionpack as well Looks like this is rolling along :-) -- choonkeat On 9/30/07, Chu Yeow Cheah <ruby-forum-incoming@andreas-s.net> wrote:> > > Awesome. Thanks for digging around! > > I''ve submitted a patch here: http://dev.rubyonrails.org/ticket/8762 > (please ignore the first patch, that''s the wrong file). > > Please take a look. > > Cheers, > Chu Yeow > > Michael Koziarski wrote: > >> Currently Hash#to_json produces text with unquoted keys, which is > invalid > >> JSON. Asking developers to set ActiveSupport:: > >> JSON.unquote_hash_key_identifiers to false if they want > >> valid JSON doesn''t seem in character of Rails, i.e. "smart defaults"... > or > >> is valid JSON the rarer requirement in common cases? > > > > I''ve dug around the history and asked a few folks an it seems there''s > > no particularly valid reason for us to continue to support the current > > behaviour. Send in a patch which switches the default and perhaps > > removes the option, and I''ll see it gets applied. > > > > -- > > Cheers > > > > Koz > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Applied. On Sep 30, 1:09 am, choonkeat <choonk...@gmail.com> wrote:> +1 and patching test in actionpack as well > > Looks like this is rolling along :-) > > -- > choonkeat > > On 9/30/07, Chu Yeow Cheah <ruby-forum-incom...@andreas-s.net> wrote: > > > > > Awesome. Thanks for digging around! > > > I''ve submitted a patch here:http://dev.rubyonrails.org/ticket/8762 > > (please ignore the first patch, that''s the wrong file). > > > Please take a look. > > > Cheers, > > Chu Yeow > > > Michael Koziarski wrote: > > >> Currently Hash#to_json produces text with unquoted keys, which is > > invalid > > >> JSON. Asking developers to set ActiveSupport:: > > >> JSON.unquote_hash_key_identifiers to false if they want > > >> valid JSON doesn''t seem in character of Rails, i.e. "smart defaults"... > > or > > >> is valid JSON the rarer requirement in common cases? > > > > I''ve dug around the history and asked a few folks an it seems there''s > > > no particularly valid reason for us to continue to support the current > > > behaviour. Send in a patch which switches the default and perhaps > > > removes the option, and I''ll see it gets applied. > > > > -- > > > Cheers > > > > Koz > > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! -- choonkeat On 10/1/07, DHH <david.heinemeier@gmail.com> wrote:> > > Applied. > > On Sep 30, 1:09 am, choonkeat <choonk...@gmail.com> wrote: > > +1 and patching test in actionpack as well > > > > Looks like this is rolling along :-) > > > > -- > > choonkeat > > > > On 9/30/07, Chu Yeow Cheah <ruby-forum-incom...@andreas-s.net> wrote: > > > > > > > > > Awesome. Thanks for digging around! > > > > > I''ve submitted a patch here:http://dev.rubyonrails.org/ticket/8762 > > > (please ignore the first patch, that''s the wrong file). > > > > > Please take a look. > > > > > Cheers, > > > Chu Yeow > > > > > Michael Koziarski wrote: > > > >> Currently Hash#to_json produces text with unquoted keys, which is > > > invalid > > > >> JSON. Asking developers to set ActiveSupport:: > > > >> JSON.unquote_hash_key_identifiers to false if they want > > > >> valid JSON doesn''t seem in character of Rails, i.e. "smart > defaults"... > > > or > > > >> is valid JSON the rarer requirement in common cases? > > > > > > I''ve dug around the history and asked a few folks an it seems > there''s > > > > no particularly valid reason for us to continue to support the > current > > > > behaviour. Send in a patch which switches the default and perhaps > > > > removes the option, and I''ll see it gets applied. > > > > > > -- > > > > Cheers > > > > > > Koz > > > > > -- > > > Posted viahttp://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
DHH wrote:> Applied.Awesome. Valid JSON at last :) Thanks Choon Keat, Michael and DHH for making this happen! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you again! On Sep 30, 8:42 pm, Chu Yeow Cheah <ruby-forum-incom...@andreas-s.net> wrote:> DHH wrote: > > Applied. > > Awesome. Valid JSON at last :) Thanks Choon Keat, Michael and DHH for > making this happen! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---