Ruby 4.1 リファレンスマニュアル

module function JSON?.dump

dump(object, io = nil, limit = nil, options = nil) -> String | IORuby 1.9.3 から[permalink][rdoc][edit]

与えられたオブジェクトを JSON 形式の文字列に変換してダンプします。

与えられたオブジェクトを引数として JSON?.generate を呼び出します。

[PARAM] object:
ダンプするオブジェクトを指定します。
[PARAM] io:
IO のように write メソッドを実装しているオブジェクトを指定します。
[PARAM] limit:
指定した場合、limit 段以上深くリンクしたオブジェクトをダンプできません。 limit は非推奨です。代わりに options の :max_nesting を指定してください。
[PARAM] options:
JSON?.generate と同じオプションをハッシュで指定します。キーワード引数の形でも指定できます。 rfc8785: true を指定した場合は、allow_nan を偽として扱います。
[EXCEPTION] JSON::NestingError:
オブジェクトのネストの深さが limit または :max_nesting を越えた場合に発生します。
例
require "json"

p JSON.dump({ name: "tanaka", age: 19 }) # => "{\"name\":\"tanaka\",\"age\":19}"
例
require "json"

File.open("test.txt", "w") do |f|
  p JSON.dump([[[[[[[[[[]]]]]]]]]], f, 10) # => #<File:test.txt>
  JSON.dump([[[[[[[[[[[]]]]]]]]]]], f, 10) # ~> nesting of 11 is too deep. Did you try to serialize objects with circular references? (JSON::NestingError)
end

[SEE_ALSO] Marshal, Marshal?.dump