I’m migrating a Ruby on Rails application from 3.0 to 3.1 and ran into some problems with the change of the JSON backend.
The line ActiveSupport::JSON.decode(some_variable) gives me the MultiJson::DecodeError nesting of 20 is too deep.
The variable I’m trying to decode is indeed heavily nested (max 29 levels).
The maximum nesting level should be changeable with the :max_nesting option ('Nesting too deep' error while retrieving JSON using HTTParty) but this doesn’t seem to work.
Both ActiveSupport::JSON.decode(some_variable, :max_nesting => false) and ActiveSupport::JSON.decode(some_variable, :max_nesting => 100) result in the same error.
Is there a way to pass the max_nesting option or set it application wide?
ActiveSupport::JSONuses the multi-json gem for encoding and decoding operations. The multi-json gem supports a variety of engines, and supported options will differ between them.You can check which engine you are using by running
Mine was
MultiJson::Adapters::Yajlbut other options are possible as well. Multi-json doesn’t seem to pass options to each engine in the same way, so I’d recommend using the JSON-gem directly.If you’re using the json-gem, you could just skip the ActiveSupport-chain and parse your data using JSON.parse, to which you can pass the
:max_nestingoption directly.