in reply to Re^2: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (PL_sv_yes PL_sv_no !!1 !!0 )
in thread Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects
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.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (source)
by davido (Cardinal) on Oct 15, 2013 at 15:39 UTC | |
by tye (Sage) on Oct 16, 2013 at 05:16 UTC | |
by davido (Cardinal) on Oct 16, 2013 at 16:43 UTC | |
by Anonymous Monk on Oct 15, 2013 at 23:10 UTC | |
|
Re^4: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (source)
by sedusedan (Pilgrim) on Oct 15, 2013 at 04:23 UTC |