/scripts/tests/json_load.pl

https://code.google.com/p/camelbox/ · Perl · 20 lines · 12 code · 5 blank · 3 comment · 1 complexity · e39cde85bfd5746f5c174bf04ef5920b MD5 · raw file

  1. #!/usr/bin/env perl
  2. # demo script to load a JSON data structure
  3. use strict;
  4. use warnings;
  5. use JSON;
  6. use Data::Dumper;
  7. my $parser = JSON->new->ascii->pretty->allow_nonref;
  8. my $json_string;
  9. while ( <STDIN> ) {
  10. # add the line to the JSON string
  11. $json_string .= $_;
  12. } # while ( <STDIN> )
  13. my $object = $parser->decode($json_string);
  14. my $dumper = Data::Dumper->new([$object]);
  15. print $dumper->Dump . qq(\n);