Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created February 27, 2012 13:51
Show Gist options
  • Save aanoaa/1923911 to your computer and use it in GitHub Desktop.
Save aanoaa/1923911 to your computer and use it in GitHub Desktop.
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