makamaka / JSON

perl implementation of JSON encoder/decoder
42 stars 40 forks source link

Can we support refs to "bool"? #19

Closed Altreus closed 8 years ago

Altreus commented 9 years ago

Perl has a special boolean false, which is simply a dualvar, zero in numeric context and the empty string in string context. You can get it from !! 0.

JSON supports \0 and \1 as shortcuts to JSON::true and JSON::false, but it would be very helpful if it could detect a ref to this dualvar and resolve accordingly.

That would turn constructs like this

($value ? \1 : \0)

into

(!! $value)

Which, although mildly awkward, seems like the sort of idiom we get in Perl, and is understandable after the first encounter.

charsbar commented 8 years ago

No. This breaks backward compatibility, and this makes it impossible to tell integer 0/1 from boolean 0/1.