Skip to content

Instantly share code, notes, and snippets.

@towbi
Created June 24, 2016 08:20
Show Gist options
  • Save towbi/42120c7846806a542bf138a7ce097a54 to your computer and use it in GitHub Desktop.
Save towbi/42120c7846806a542bf138a7ce097a54 to your computer and use it in GitHub Desktop.
Simple demo use of Perl's JSON-module
#!/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