-
-
Save aanoaa/1923911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use JSON; | |
my $perl_scalar = { | |
foo => 1, | |
bar => [1, 2, 3], | |
baz => { | |
oops => { | |
abc => 'tiger' | |
} | |
} | |
}; | |
my $json_text = to_json( $perl_scalar, { ascii => 1, pretty => 1 } ); | |
print "$json_text\n"; | |
__DATA__ | |
{ | |
"bar" : [ | |
1, | |
2, | |
3 | |
], | |
"baz" : { | |
"oops" : { | |
"abc" : "tiger" | |
} | |
}, | |
"foo" : 1 | |
} | |
use strict; | |
use warnings; | |
use File::Slurp qw/slurp/; | |
use Data::Printer; | |
use JSON; | |
my $json = slurp 'a.json'; | |
my $perl_scalar = from_json( $json, { utf8 => 1 } ); | |
p $perl_scalar; | |
__DATA__ | |
\ { | |
bar [ | |
[0] 1, | |
[1] 2, | |
[2] 3 | |
], | |
baz { | |
oops { | |
abc "tiger" | |
} | |
}, | |
foo 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment