# Request.env.to\_hash.to\_json breaking

**URL:** <https://www.ruby-forum.com/t/request-env-to-hash-to-json-breaking/172992>\
**Category:** Rails\
**Created:** [July 30, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/request-env-to-hash-to-json-breaking/172992 "2009-07-30T22:19:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![subv3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@subv3](https://www.ruby-forum.com/u/subv3)\
**Post date:** [July 30, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/request-env-to-hash-to-json-breaking/172992/1 "2009-07-30T22:19:02Z")

</div>

Hi,

I’ve been on this for a bit now trying to find out why this breaks but  
I can’t. Hopefully someone else will have some idea.

I’ve been compiling a hash of which one of the objects is request.env.  
I then call #to\_json on the hash but it fails with:

“You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.pop”

Calling #to\_json on request.env.to\_hash also fails with error “stack  
level too deep”.

From the backtrace you can see a loop of the following happening:

/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active\_support/  
json/encoding.rb:69:in `encode' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/ json/encoding.rb:19:in` **send** ’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active\_support/  
json/encoding.rb:19:in `encode' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/ json/encoders/hash.rb:38:in`to\_json’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action\_view/  
renderable.rb:77:in `map’

Anyone have any thoughts on this?

Thanks
