I was hoping that there would be a way to do it without going to the source.
How were you going to figure this out without going to the source?
Going to the source, I saw that it is possible to change what JSON::XS returns for 'true' and 'false', if you get your stuff run at the right time. For example:
use XSLoader;
BEGIN {
my $load = \&XSLoader::load;
sub load {
*JSON::XS::true = *true;
*JSON::XS::false = *false;
goto &$load;
}
*XSLoader::load = *load;
our( $true, $false ) = \( 1, 0 );
sub true() { $true }
sub false() { $false }
}
use JSON::XS();
print ref($_), ' ', $_, $/ for @{
JSON::XS->new()->decode('["0","1",true,false]')
};
But JSON::XS blithely assumes that $JSON::XS::true (and ...false) will contain references. If you adjust my code above so that they don't contain references, then as soon as you try to decode JSON containing 'true' or 'false', you'll get a core dump.
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.
|