my $json_output = encode_json($data_structure);
- my $json = JSON->new;
+ my $json = JSON()->new;
my $json_with_args = JSON::MaybeXS->new(utf8 => 1); # or { utf8 => 1 }
The C<JSON> constant returns the selected implementation module's name for
use as a class name - so:
- my $json_obj = JSON->new; # returns a Cpanel::JSON::XS or JSON::PP object
+ my $json_obj = JSON()->new; # returns a Cpanel::JSON::XS or JSON::PP object
and that object can then be used normally:
my $data_structure = $json_obj->decode($json_text); # etc.
+The use of parentheses here is optional, and only used as a hint to the reader
+that this use of C<JSON> is a I<subroutine> call, I<not> a class name.
+
=head2 is_bool
$is_boolean = is_bool($scalar)
To include JSON-aware booleans (C<true>, C<false>) in your data, just do:
use JSON::MaybeXS;
- my $true = JSON->true;
- my $false = JSON->false;
+ my $true = JSON()->true;
+ my $false = JSON()->false;
=head1 CONVERTING FROM JSON::Any
This function call is functionally identical to:
- $json_text = JSON->new->encode($perl_scalar)
+ $json_text = JSON()->new->encode($perl_scalar)
from_json
$perl_scalar = from_json($json_text)
This function call is functionally identical to:
- $perl_scalar = JSON->decode($json_text)
+ $perl_scalar = JSON()->decode($json_text)
plan skip_all => 'No JSON';
}
-my $data = JSON->new->decode('{"foo": true, "bar": false, "baz": 1}');
+my $data = JSON()->new->decode('{"foo": true, "bar": false, "baz": 1}');
ok(
JSON::is_bool($data->{foo}),