module JSON

def dump(obj, anIO = nil, limit = nil, kwargs = nil)

{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
Output:
puts File.read(path)
end # => #
JSON.dump(obj, file)
File.open(path, 'w') do |file|
path = 't.json'
When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:

json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
json = JSON.dump(obj)
obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
When argument +io+ is not given, returns the \JSON \String generated from +obj+:

---

- Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
If +io+ is not given, the \JSON \String is returned.
the \JSON \String is written to +io+, and +io+ is returned.
- Argument +io+, if given, should respond to method +write+;

The default options can be changed via method JSON.dump_default_options.

Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.

JSON.dump(obj, io = nil, limit = nil)
:call-seq:
def dump(obj, anIO = nil, limit = nil, kwargs = nil)
  if kwargs.nil?
    if limit.nil?
      if anIO.is_a?(Hash)
        kwargs = anIO
        anIO = nil
      end
    elsif limit.is_a?(Hash)
      kwargs = limit
      limit = nil
    end
  end
  unless anIO.nil?
    if anIO.respond_to?(:to_io)
      anIO = anIO.to_io
    elsif limit.nil? && !anIO.respond_to?(:write)
      anIO, limit = nil, anIO
    end
  end
  opts = JSON._dump_default_options
  opts = opts.merge(:max_nesting => limit) if limit
  opts = opts.merge(kwargs) if kwargs
  begin
    State.generate(obj, opts, anIO)
  rescue JSON::NestingError
    raise ArgumentError, "exceed depth limit"
  end
end