- or download this
use JSON;
my $json = '{ "o": "hai", "hurr": "derp" }';
my $data = decode_json( $json );
print $data->{o}, $/; # Prints "hai"
- or download this
print encode_json($data), $/;
# Prints: {"hurr":"derp","o":"hai"}
- or download this
# Some plain Perl-
my @stuf = ( 1, 2, 3 ); # Or, idiomatically ( 1..3 )
print encode_json(\@stuf), $/; # Need \ to take reference.
# Same outcome as [] for array ref plus 1..3-
print encode_json( [ 1 .. 3 ] ), $/;
- or download this
{"OWNER":"KeyProjects","age1":"eon","ht1":"moo","wc":"EF1"}
- or download this
{"OWNER":"KeyProjects","scheduled":{"age1":"eon","ht1":"moo"},"wc":"EF
+1"}
- or download this
use warnings;
use strict;
...
print encode_json( $data ), $/;
# {"scheduled":{"age1":"eon","ht1":"moo"},"OWNER":"KeyProjects"}
# Remember, order is irrelevant in Objects.
- or download this
use warnings;
use strict;
...
}
print encode_json( $data ), $/;
- or download this
use Test::More;
my $desired_data = decode_json( $desired );
is_deeply( $desired_data, $data, "Data structures match" );
done_testing(1);