End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
JSON#fast_generate
JSON.fast_generate(obj, opts) → new_string
ext/json/lib/json/common.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/ext/json/lib/json/common.rb, line 335
def fast_generate(obj, opts = nil)
if State === opts
state, opts = opts, nil
else
state = JSON.create_fast_state
end
if opts
if opts.respond_to? :to_hash
opts = opts.to_hash
elsif opts.respond_to? :to_h
opts = opts.to_h
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
state.configure(opts)
end
state.generate(obj)
end
Arguments obj and opts here are the same as arguments obj and opts in JSON.generate.
By default, generates JSON data without checking for circular references in obj (option max_nesting set to false, disabled).
Raises an exception if obj contains circular references:
Example
a = []; b = []; a.push(b); b.push(a) # Raises SystemStackError (stack level too deep): JSON.fast_generate(a)