# File lib/json/pure/generator.rb, line 299
299:           def to_json(state = nil, depth = 0, *)
300:             if state
301:               state = JSON.state.from_state(state)
302:               state.check_max_nesting(depth)
303:               json_check_circular(state) { json_transform(state, depth) }
304:             else
305:               json_transform(state, depth)
306:             end
307:           end