Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > jsonライブラリ > JSON::Stateクラス > max_nesting

instance method JSON::State#max_nesting

max_nesting -> Integer[permalink][rdoc]

生成される JSON 形式の文字列のネストの深さの最大値を返します。

この値がゼロである場合は、ネストの深さのチェックを行いません。

例 ネストの深さチェックを行う

require "json"

json_state = JSON::State.new(max_nesting: 2)
json_state.max_nesting            # => 2
JSON.generate([[]], json_state)
JSON.generate([[[]]], json_state) # => JSON::NestingError
例 ネストの深さチェックを行わない

require "json"

json_state = JSON::State.new(max_nesting: 0)
json_state.max_nesting            # => 0
JSON.generate([[[[[[[[[[]]]]]]]]]], json_state)