Skip to content

Commit

Permalink
better Mojo::JSON examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 19, 2014
1 parent 6a05f16 commit 28534a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,4 +1,6 @@

4.84 2014-02-20

4.83 2014-02-19
- Improved Mojo::JSON to handle encoding errors more gracefully.
- Fixed line numbers in Mojo::JSON error messages.
Expand Down
13 changes: 6 additions & 7 deletions lib/Mojo/JSON.pm
Expand Up @@ -326,19 +326,18 @@ Mojo::JSON - Minimalistic JSON
=head1 SYNOPSIS
use Mojo::JSON;
use Mojo::JSON qw(decode_json encode_json);
# Encode and decode JSON
my $json = Mojo::JSON->new;
my $bytes = $json->encode({foo => [1, 2], bar => 'hello!', baz => \1});
my $hash = $json->decode($bytes);
# Encode and decode JSON (die on errors)
my $bytes = encode_json({foo => [1, 2], bar => 'hello!', baz => \1});
my $hash = decode_json($bytes);
# Check for errors
# Handle errors
my $json = Mojo::JSON->new;
if (defined(my $hash = $json->decode($bytes))) { say $hash->{message} }
else { say 'Error: ', $json->error }
# Use the alternative interface
# Ignore errors
use Mojo::JSON 'j';
my $bytes = j({foo => [1, 2], bar => 'hello!', baz => \1});
my $hash = j($bytes);
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -43,7 +43,7 @@ has types => sub { Mojolicious::Types->new };
has validator => sub { Mojolicious::Validator->new };

our $CODENAME = 'Top Hat';
our $VERSION = '4.83';
our $VERSION = '4.84';

sub AUTOLOAD {
my $self = shift;
Expand Down

0 comments on commit 28534a1

Please sign in to comment.