require "json"
def convert_to_json(obj)
obj.to_json
end
p convert_to_json(1) # => "1"
p convert_to_json("x") # => "\"x\""
% ruby 1.rb
"1"
"\"x\""
% crystal 1.rb
"1"
"\"x\""
require "json"
def convert_to_json(obj)
obj.to_json
end
p convert_to_json(/x/)
% ruby 2.rb
"\"(?-mix:x)\""
% crystal build 2.rb
...
in /usr/share/crystal/src/json/to_json.cr:10: no overload matches 'Regex#to_json' with type JSON::Builder
Overloads are:
- Object#to_json(io : IO)
- Object#to_json()
to_json(json)