NAME
Mojo::JSON::Pointer - JSON Pointers
SYNOPSIS
use Mojo::JSON::Pointer;
my $pointer = Mojo::JSON::Pointer->new({foo => [23, 'bar']});
say $pointer->get('/foo/1');
say 'Contains "/foo".' if $pointer->contains('/foo');
DESCRIPTION
Mojo::JSON::Pointer is a relaxed implementation of RFC 6901.
ATTRIBUTES
Mojo::JSON::Pointer implements the following attributes.
data
my $data = $pointer->data;
$pointer = $pointer->data({foo => 'bar'});
Data to be processed.
METHODS
Mojo::JSON::Pointer inherits all methods from Mojo::Base and implements the following new ones.
contains
my $bool = $pointer->contains('/foo/1');
my $bool = $pointer->contains($data, '/foo/1');
Check if Perl data structure contains a value that can be identified with the given JSON Pointer, defaults to using "data".
# True
$pointer->contains({'♥' => 'mojolicious'}, '/♥');
$pointer->contains({foo => 'bar', baz => [4, 5, 6]}, '/foo');
$pointer->contains({foo => 'bar', baz => [4, 5, 6]}, '/baz/2');
# False
$pointer->contains({'♥' => 'mojolicious'}, '/☃');
$pointer->contains({foo => 'bar', baz => [4, 5, 6]}, '/bar');
$pointer->contains({foo => 'bar', baz => [4, 5, 6]}, '/baz/9');
get
my $value = $pointer->get('/foo/bar');
my $value = $pointer->get($data, '/foo/bar');
Extract value identified by the given JSON Pointer, defaults to using "data".
# "mojolicious"
$pointer->get({'♥' => 'mojolicious'}, '/♥');
# "bar"
$pointer->get({foo => 'bar', baz => [4, 5, 6]}, '/foo');
# "4"
$pointer->get({foo => 'bar', baz => [4, 5, 6]}, '/baz/0');
# "6"
$pointer->get({foo => 'bar', baz => [4, 5, 6]}, '/baz/2');
new
my $pointer = Mojo::JSON::Pointer->new;
my $pointer = Mojo::JSON::Pointer->new({foo => 'bar'});
Build new Mojo::JSON::Pointer object.