Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

JSON::GeneratorMethods#to_json

to_json(*)

Converts this object into a JSON string. If this object doesn’t directly maps to a JSON native type, first convert it to a string (calling to_s), then converts it to a JSON string, and returns the result. This is a fallback, if no special method to_json was defined for some object.