Help for this page

Select Code to Download


  1. or download this
    use JSON;
    my $json = '{ "o": "hai", "hurr": "derp" }';
    my $data = decode_json( $json );
    print $data->{o}, $/; # Prints "hai"
    
  2. or download this
    print encode_json($data), $/;
    # Prints: {"hurr":"derp","o":"hai"}
    
  3. or download this
    # Some plain Perl-
    my @stuf = ( 1, 2, 3 ); # Or, idiomatically ( 1..3 )
    print encode_json(\@stuf), $/; # Need \ to take reference.
    # Same outcome as [] for array ref plus 1..3-
    print encode_json( [ 1 .. 3 ] ), $/;
    
  4. or download this
    {"OWNER":"KeyProjects","age1":"eon","ht1":"moo","wc":"EF1"}
    
  5. or download this
    {"OWNER":"KeyProjects","scheduled":{"age1":"eon","ht1":"moo"},"wc":"EF
    +1"}
    
  6. or download this
    use warnings;
    use strict;
    ...
    print encode_json( $data ), $/;
    # {"scheduled":{"age1":"eon","ht1":"moo"},"OWNER":"KeyProjects"}
    # Remember, order is irrelevant in Objects.
    
  7. or download this
    use warnings;
    use strict;
    ...
    }
    
    print encode_json( $data ), $/;
    
  8. or download this
    use Test::More;
    my $desired_data = decode_json( $desired );
    is_deeply( $desired_data, $data, "Data structures match" );
    done_testing(1);