module JSON
def generate(obj, opts = nil)
JSON.generate(a)
# Raises JSON::NestingError (nesting of 100 is too deep):
a = []; b = []; a.push(b); b.push(a)
Raises an exception if +obj+ contains circular references:
Raises an exception if any formatting option is not a \String.
---
{Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
For examples of generating from other Ruby objects, see
json # => '{"foo":0,"bar":"s","baz":"bat"}'
json = JSON.generate(obj)
obj = {foo: 0, bar: 's', baz: :bat}
When +obj+ is a \Hash, returns a \String containing a \JSON object:
json # => '["foo",1.0,true,false,null]'
json = JSON.generate(obj)
obj = ["foo", 1.0, true, false, nil]
When +obj+ is an \Array, returns a \String containing a \JSON array:
---
See {Generating Options}[#module-JSON-label-Generating+Options].
Argument +opts+, if given, contains a \Hash of options for the generation.
Argument +obj+ is the Ruby object to be converted to \JSON.
See also JSON.fast_generate, JSON.pretty_generate.
Returns a \String containing the generated \JSON data.
JSON.generate(obj, opts = nil) -> new_string
:call-seq:
def generate(obj, opts = nil) if State === opts opts.generate(obj) else State.generate(obj, opts, nil) end end