Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
BigDecimal#to_json
to_json(*args)
ext/json/lib/json/add/bigdecimal.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/json/lib/json/add/bigdecimal.rb, line 55
def to_json(*args)
as_json.to_json(*args)
end
Returns a JSON string representing self:
Example
require 'json/add/bigdecimal' puts BigDecimal(2).to_json puts BigDecimal(2.0, 4).to_json puts BigDecimal(Complex(2, 0)).to_json
Output:
Example
{"json_class":"BigDecimal","b":"27:0.2e1"}
{"json_class":"BigDecimal","b":"36:0.2e1"}
{"json_class":"BigDecimal","b":"27:0.2e1"}