in reply to Re^3: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (source)
in thread Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects
If I were you, I'd just use something much simpler like JSON::Tiny. And I'd file a patch request to have "my $TRUE" changed to "our $TRUE", etc.
Minimally, I've implemented this in JSON::Tiny version 0.33, uploaded to CPAN just a few minutes ago. my $TRUE... is now our $TRUE, so that users may explicitly override the return value for Booleans. The same goes for my $FALSE.
If there is sufficient call for it, I might also provide additional flexibility in _encode_value() by changing this line: return $value ? 'true' : 'false' if $ref eq 'JSON::Tiny::_Bool'; to something like return $value ? 'true' : 'false' if $ref eq $BOOL_CLASS; # A package global. Once we go too far down that road, however, people are going to start asking that $TRUE, $FALSE, and $BOOL_CLASS be implemented as object attributes for the JSON::Tiny object so that they can be manipulated on a per-instance basis... and that leads to becoming less '::Tiny'. ;)
For now just consider the following code:
use JSON::Tiny; $JSON::Tiny::FALSE = 0; $JSON::Tiny::TRUE = 1; my $j = JSON::Tiny->new(); # ... Booleans in JSON being decoded now return 0 and 1 instead of # JSON::Tiny::Bool objects
Update: Version 0.34 adds some tests and documentation on this advanced feature.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (\$)
by tye (Sage) on Oct 16, 2013 at 05:16 UTC | |
by davido (Cardinal) on Oct 16, 2013 at 16:43 UTC | |
|
Re^5: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (source)
by Anonymous Monk on Oct 15, 2013 at 23:10 UTC |