Hi there, I am fairly new to the Rails framework, so forgive me if there is an obvious solution to this problem. I am using Rails 2.1.0 and trying to jsonify a hash containing an array. E.g.>> result = { :name => "McLovin", :attachments => [''file.pdf'', ''file.jpg''] }=> {:attachments=>["file.pdf", "file.jpg"], :name=>"McLovin"}>> result.to_jsonI would expect something like: { "name": "McLovin", "attachments": [ "file.pdf", "file.jpg" ] } But instead I get: TypeError: wrong argument type Hash (expected Data) from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `send'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `encode'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:31:in `raise_on_circular_reference'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:20:in `encode'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:42:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:41:in `map'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:41:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/core_ext/object/misc.rb:28:in `returning'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:40:in `to_json'' from (irb):54>>If I do "result.to_json( :except => :attachments )", then it works. Best regards, Mads Kristiansen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi there, I am fairly new to the Rails framework, so forgive me if there is an obvious solution to this problem. I am using Rails 2.1.0 and trying to jsonify a hash containing an array. E.g. result = { :name => "McLovin", :attachments => [''file.pdf'', ''file.jpg''] } => {:attachments=>["file.pdf", "file.jpg"], :name=>"McLovin"} result.to_json I would expect something like: { "name": "McLovin", "attachments": [ "file.pdf", "file.jpg" ] } But instead I get: TypeError: wrong argument type Hash (expected Data) from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `send'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:21:in `encode'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:31:in `raise_on_circular_reference'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoding.rb:20:in `encode'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:42:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:41:in `map'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:41:in `to_json'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/core_ext/object/misc.rb:28:in `returning'' from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ active_support/json/encoders/hash.rb:40:in `to_json'' from (irb):54 If I do "result.to_json( :except => :attachments )", then it works. Best regards, Mads Kristiansen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 Aug 2008, at 13:41, Mads Kristiansen wrote:> > Hi there, > > I am fairly new to the Rails framework, so forgive me if there is an > obvious solution to this problem. > > I am using Rails 2.1.0 and trying to jsonify a hash containing an > array. E.g. > > result = { :name => "McLovin", :attachments => [''file.pdf'', > ''file.jpg''] } > => {:attachments=>["file.pdf", "file.jpg"], :name=>"McLovin"} > result.to_json > > I would expect something like: > > { > "name": "McLovin", > "attachments": [ > "file.pdf", > "file.jpg" > ] > }Which is exactly what I got when I tried this out. Do you have any plugins/use any gems that could be clashing with activesupport''s JSON stuff? Fred> > > But instead I get: > > TypeError: wrong argument type Hash (expected Data) > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoding.rb:21:in `to_json'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoding.rb:21:in `send'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoding.rb:21:in `encode'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoding.rb:31:in `raise_on_circular_reference'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoding.rb:20:in `encode'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoders/hash.rb:42:in `to_json'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoders/hash.rb:41:in `map'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoders/hash.rb:41:in `to_json'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/core_ext/object/misc.rb:28:in `returning'' > from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > active_support/json/encoders/hash.rb:40:in `to_json'' > from (irb):54 > > > If I do "result.to_json( :except => :attachments )", then it works. > > Best regards, Mads Kristiansen > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- >
Okay, thanks. Just wanted to confirm that it actually worked somewhere.. :) I removed the "json_pure" gem and now it works for me too.. Not sure if that will cause other problems, but we''ll see about that. Best regards, Mads Kristiansen On 24/08/2008, at 19.32, Frederick Cheung wrote:> > On 24 Aug 2008, at 13:41, Mads Kristiansen wrote: > >> >> Hi there, >> >> I am fairly new to the Rails framework, so forgive me if there is an >> obvious solution to this problem. >> >> I am using Rails 2.1.0 and trying to jsonify a hash containing an >> array. E.g. >> >> result = { :name => "McLovin", :attachments => [''file.pdf'', >> ''file.jpg''] } >> => {:attachments=>["file.pdf", "file.jpg"], :name=>"McLovin"} >> result.to_json >> >> I would expect something like: >> >> { >> "name": "McLovin", >> "attachments": [ >> "file.pdf", >> "file.jpg" >> ] >> } > Which is exactly what I got when I tried this out. Do you have any > plugins/use any gems that could be clashing with activesupport''s > JSON stuff? > > Fred >> >> >> But instead I get: >> >> TypeError: wrong argument type Hash (expected Data) >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoding.rb:21:in `to_json'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoding.rb:21:in `send'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoding.rb:21:in `encode'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoding.rb:31:in `raise_on_circular_reference'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoding.rb:20:in `encode'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoders/hash.rb:42:in `to_json'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoders/hash.rb:41:in `map'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoders/hash.rb:41:in `to_json'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/core_ext/object/misc.rb:28:in `returning'' >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ >> active_support/json/encoders/hash.rb:40:in `to_json'' >> from (irb):54 >> >> >> If I do "result.to_json( :except => :attachments )", then it works. >> >> Best regards, Mads Kristiansen >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is also a problem in Merb. I believe AR''s json and Merb''s json don''t play well together. I put this in init.rb and now life is grand. Merb.disable :json On Aug 24, 1:04 pm, Mads Kristiansen <mads.kristian...-ORde088ZbSZWk0Htik3J/w@public.gmane.org> wrote:> Okay, thanks. Just wanted to confirm that it actually worked > somewhere.. :) > > I removed the "json_pure" gem and now it works for me too.. Not sure > if that will cause other problems, but we''ll see about that. > > Best regards, Mads Kristiansen > > On 24/08/2008, at 19.32, Frederick Cheung wrote: > > > > > > > On 24 Aug 2008, at 13:41, Mads Kristiansen wrote: > > >> Hi there, > > >> I am fairly new to the Rails framework, so forgive me if there is an > >> obvious solution to this problem. > > >> I am using Rails 2.1.0 and trying to jsonify a hash containing an > >> array. E.g. > > >> result = { :name => "McLovin", :attachments => [''file.pdf'', > >> ''file.jpg''] } > >> => {:attachments=>["file.pdf", "file.jpg"], :name=>"McLovin"} > >> result.to_json > > >> I would expect something like: > > >> { > >> "name": "McLovin", > >> "attachments": [ > >> "file.pdf", > >> "file.jpg" > >> ] > >> } > > Which is exactly what I got when I tried this out. Do you have any > > plugins/use any gems that could be clashing with activesupport''s > > JSON stuff? > > > Fred > > >> But instead I get: > > >> TypeError: wrong argument type Hash (expected Data) > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoding.rb:21:in `to_json'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoding.rb:21:in `send'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoding.rb:21:in `encode'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoding.rb:31:in `raise_on_circular_reference'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoding.rb:20:in `encode'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoders/hash.rb:42:in `to_json'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoders/hash.rb:41:in `map'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoders/hash.rb:41:in `to_json'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/core_ext/object/misc.rb:28:in `returning'' > >> from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/ > >> active_support/json/encoders/hash.rb:40:in `to_json'' > >> from (irb):54 > > >> If I do "result.to_json( :except => :attachments )", then it works. > > >> Best regards, Mads Kristiansen--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---