Skip to content
instance method

BigDecimal#to_json

(?::JSON::State? state) -> ::String
to_json(*args)

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"}
See also #as_json .json_create also in 3.4 · 3.3 · 3.2 · 3.1 · 3.0