2023-03-05 23:42:45

This commit is contained in:
2023-03-05 23:42:45 +09:00
parent 25b3c0eb79
commit 9e97869a9d
15 changed files with 326 additions and 0 deletions

22
src/json.pl Executable file
View File

@@ -0,0 +1,22 @@
#! /usr/bin/perl
use strict;
use JSON; # https://metacpan.org/pod/JSON
# sudo cpanm JSON
## from json to hash
my $json = <<JSON;
{
"name":"charlie",
"age":13
}
JSON
my $obj = &decode_json($json); # returns a reference to a hash
print "NAME: $obj->{'name'}\n";
print "AGE: $obj->{'age'}\n";
## from hash to json
my %person = ('name'=>'Steve', 'age'=>34);
my $text = &encode_json(\%person); # pass a reference to a hash
print "JSON TEXT: $text\n";