To dump arrays, hashes, and objects (converted to_hash ), these three methods are equivalent.
But JSON.generate or JSON.dump only arrays, hashes and objects are allowed.
to_json accepts many Ruby classes, although it only acts as a method for serialization, for example an integer:
JSON.generate 1 # would be allowed 1.to_json # => "1"
JSON.generate took more options for the output style (e.g. space, indent)
And JSON.dump , print the default style, but take the object as the second argument for writing as the second argument, the third argument as the limit of the number of nested arrays or objects.
aligo source share