Created
June 24, 2016 08:20
-
-
Save towbi/42120c7846806a542bf138a7ce097a54 to your computer and use it in GitHub Desktop.
Simple demo use of Perl's JSON-module
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
#!/usr/bin/env perl | |
use JSON; | |
use Data::Dumper; | |
my $hash = { | |
foo => 'bar', | |
baz => { | |
'noch eine' => 'hash map', | |
'abc' => 42 | |
}, | |
qux => [ | |
'auch', | |
'arrays', | |
'funktionieren' | |
] | |
}; | |
my $json = JSON->new; | |
print "Perl-Datenstruktur:\n"; | |
print Dumper($hash); | |
print "\n\n"; | |
print "JSON-String ohne pretty-printing:\n"; | |
print $json->encode($hash); | |
print "\n\n"; | |
print "Mit pretty-printing (menschenlesbarer, größer):\n"; | |
$json->pretty; | |
print $json->encode($hash); | |
print "\n\n"; | |
print "Dekodierung:\n"; | |
my $encoded_json = $json->encode($hash); | |
my $decoded_json = $json->decode($encoded_json); | |
print Dumper($decoded_json); | |
print "\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment