Subject: | Big Number 0 should not Encode as a String |
Date: | Tue, 12 Nov 2013 15:36:46 -0800 |
To: | bug-json [...] rt.cpan.org |
From: | "David E. Wheeler" <dwheeler [...] cpan.org> |
With `allow_bignum`, BigFloats and BigInts usually properly encode as JSON numbers.
Show quoted text
> perl -MJSON::PP -MMath::BigInt -MMath::BigFloat -E 'say JSON::PP->new->allow_bignum->encode([Math::BigInt->new("1"), Math::BigFloat->new("1.0")])'
[1,1]
Looks good. But change those values to 0s and it's not so good:
Show quoted text > perl -MJSON::PP -MMath::BigInt -MMath::BigFloat -E 'say JSON::PP->new->allow_bignum->encode([Math::BigInt->new("0"), Math::BigFloat->new("0.0")])'
["0","0"]
Oops! Why are those zeros encoded as JSON strings? Not sure if it's something in the Math::Big* modules or JSON, but either way, it's not what I would expect.
Best,
David
PS: Would love to see bignum support in JSON::XS, too!