Project

General

Profile

Actions

Bug #19686

closed

BigDecimal object returns JSON string

Bug #19686: BigDecimal object returns JSON string

Added by goh (Goh Matsumoto) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]
[ruby-dev:<unknown>]

Description

Hi,

When I call the to_json method to the BigDecimal object, it returns a JSON string.
Is this intentional?

> ruby -v -rbigdecimal -rjson -e 'p BigDecimal("1.2").to_json'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]
"\"0.12e1\""
> ruby -v -rjson/add/bigdecimal -e 'p BigDecimal("1.2").to_json'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]
"{\"json_class\":\"BigDecimal\",\"b\":\"18:0.12e1\"}"

I expect a JSON number like "0.12e1".

Actions

Also available in: PDF Atom