Method: JSON.dump
- Defined in:
- lib/vendor/json_pure/lib/json/common.rb
.dump(obj, anIO = nil, limit = nil) ⇒ Object
Dumps obj as a JSON string, i.e. calls generate on the object and returns the result.
If anIO (an IO like object or an object that responds to the write method) was given, the resulting JSON is written to it.
If the number of nested arrays or objects exceeds limit an ArgumentError exception is raised. This argument is similar (but not exactly the same!) to the limit argument in Marshal.dump.
This method is part of the implementation of the load/dump interface of Marshal and YAML.
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/vendor/json_pure/lib/json/common.rb', line 327 def dump(obj, anIO = nil, limit = nil) if anIO and limit.nil? anIO = anIO.to_io if anIO.respond_to?(:to_io) unless anIO.respond_to?(:write) limit = anIO anIO = nil end end limit ||= 0 result = generate(obj, :allow_nan => true, :max_nesting => limit) if anIO anIO.write result anIO else result end rescue JSON::NestingError raise ArgumentError, "exceed depth limit" end |