I am writing a very simple proxy wrapper for the reddit api so I can make cross domain JSONP requests (reddit does not allow JSONP calls to my knowledge).
I am using
It looks like this can be worked around by calling to_json
with the max_nesting
option set.
json = obj.to_json(max_nesting: 50)
It's not that the JSON is too large. It's nested too deeply. HTTParty
tries to decode the results that it gets automatically. Following your stack trace, and the HTTParty
dependencies, it relies on multi_json
which is using the json
gem.
Inside of json
there is lib/json/pure/parser.rb. The default max depth set is set in there, specifically on line 79. Something in your returned JSON is 20+ levels deep, triggering the exception.
if !opts.key?(:max_nesting) # defaults to 19
@max_nesting = 19
Switched to the OJ JSON parser by adding the following to my Gemfile:
gem 'oj'
and this issue resolved itself.