Sample code for 30+ languages & platforms
Perl

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# Create JSON with members of different data types.
my $json = Chilkat2::JsonObject->new;

$json->UpdateInt('a', 123);
$json->UpdateBool('b', 1);
$json->UpdateNull('c');

$json->EmitCompact(0);
print $json->Emit(), "\n";

# Resulting JSON:
# {
#   "a": 123,
#   "b": true,
#   "c": null
# }

my $a = $json->StringOf('a');
print $a, "\n";

my $b = $json->StringOf('b');
print $b, "\n";

my $c = $json->StringOf('c');
print $c, "\n";

# Output

# 123
# true
# null

# If you want to get the integer, boolean, or null value
# you need to use the methods matching the data type
my $ival = $json->IntOf('a');
my $bval = $json->BoolOf('b');
my $hasNull = $json->IsNullOf('c');