Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

how to decode JSON::PP::Boolean

by gabrielsousa (Sexton)
on Dec 06, 2017 at 15:55 UTC ( [id://1205018]=perlquestion: print w/replies, xml ) Need Help??

gabrielsousa has asked for the wisdom of the Perl Monks concerning the following question:

i have this string
$VAR1 = \bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' );
use JSON; $decodejattch = $decoded2->{HasAttachments}; $decodejattch = JSON::decode_json $decodejattch;
i have this error:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `echo "malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at ./test-mail365.pl line 102.'
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at ./test-mail365.pl line 102.

Replies are listed 'Best First'.
Re: how to decode JSON::PP::Boolean
by tangent (Parson) on Dec 06, 2017 at 16:46 UTC
    The value you are retrieving from $decoded2->{HasAttachments} needs to be treated as a true or false value in your code - it does not need further decoding:
    use JSON; use Data::Dumper; my $json = encode_json( {HasAttachments => \0} ); # \0 is JSON false my $decoded = decode_json( $json ); print Dumper( $decoded->{HasAttachments} ); if ( $decoded->{HasAttachments} ) { print "HasAttachments is true"; } else { print "HasAttachments is false"; } # Prints: $VAR1 = bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ); HasAttachments is false
Re: how to decode JSON::PP::Boolean
by Corion (Patriarch) on Dec 06, 2017 at 15:58 UTC

    If you see the error sh -c ..., then that means that your file is being run by the shell and not by Perl.

    The code you show does not have 102 lines and does not look as if it is run by your shell at all. Please show a short, self-contained program (and the JSON input) that reproduces the output.

Re: how to decode JSON::PP::Boolean
by Eily (Monsignor) on Dec 06, 2017 at 16:08 UTC

    Corion++. Also your string is perl code, JSON can't do anything with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1205018]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found