makamaka / JSON

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

Option to downgrade booleans to 0 and 1 #20

Closed Altreus closed 8 years ago

Altreus commented 9 years ago

In my tests I have to do something like this:

for (values $href) {
  $_ = int !!$_ if JSON::is_bool($_);
}

So that Test::Differences::eq_or_diff doesn't consider the blessed boolean thingies to be different from the 0 and 1 (or \0 and \1) I'm using in the first place.

A setting that downgrades the true and false atoms to simple scalars (perhaps customisable) would be very useful in this situation.

charsbar commented 8 years ago

This is rather an issue of how to write your tests, not JSON.pm and its backends. Boolean values should not be downgraded to integers, because you can't tell integer 0/1 from converted boolean 0/1 in general.