# Help for hash.to\_json

**URL:** <https://www.ruby-forum.com/t/help-for-hash-to-json/122719>\
**Category:** Rails\
**Created:** [December 11, 2007, 9:20am UTC](https://www.ruby-forum.com/t/help-for-hash-to-json/122719 "2007-12-11T09:20:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ao\_tianlong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c89c15/32.png) [@ao\_tianlong](https://www.ruby-forum.com/u/ao_tianlong)\
**Post date:** [December 11, 2007, 9:20am UTC](https://www.ruby-forum.com/t/help-for-hash-to-json/122719/1 "2007-12-11T09:20:56Z")

</div>

hi , all  
under rails 2.0

aotianlong@aotianlong:~/workspace/killer$ ruby script/console  
Loading development environment (Rails 2.0.1)

> > {:user=\>“aotianlong”}.to\_json  
> > =\> “{“user”: “aotianlong”}”
> 
> > user = User.find :first  
> > =\> #\<User id: 1, uname: “aotianlong”\>
> 
> > user.to\_json  
> > =\> “{“attributes”: {“id”:1,“uname”: “aotianlong”}}”
> 
> > {:user=\>user}.to\_json  
> > ArgumentError: wrong number of arguments (1 for 0)  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/json/encoding.rb:22:in  
> > `to_json' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:22:in`send’  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/json/encoding.rb:22:in  
> > `encode' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:32:in`raise\_on\_circular\_reference’  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/json/encoding.rb:21:in  
> > `encode' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:45:in`to\_json’  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/json/encoders/hash.rb:44:in  
> > `map' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:44:in`to\_json’  
> > from  
> > /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active\_support/core\_ext/object/misc.rb:28:in  
> > `returning' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:43:in`to\_json’  
> > from (irb):4
> 
> >

how let {:user=\>user}.to\_json work correct?

thanks for reply.
