1Mojo::JSON::Pointer(3)User Contributed Perl DocumentationMojo::JSON::Pointer(3)
2
3
4

NAME

6       Mojo::JSON::Pointer - JSON Pointers
7

SYNOPSIS

9         use Mojo::JSON::Pointer;
10
11         my $pointer = Mojo::JSON::Pointer->new({foo => [23, 'bar']});
12         say $pointer->get('/foo/1');
13         say 'Contains "/foo".' if $pointer->contains('/foo');
14

DESCRIPTION

16       Mojo::JSON::Pointer is an implementation of RFC 6901
17       <http://tools.ietf.org/html/rfc6901>.
18

ATTRIBUTES

20       Mojo::JSON::Pointer implements the following attributes.
21
22   data
23         my $data = $pointer->data;
24         $pointer = $pointer->data({foo => 'bar'});
25
26       Data structure to be processed.
27

METHODS

29       Mojo::JSON::Pointer inherits all methods from Mojo::Base and implements
30       the following new ones.
31
32   contains
33         my $bool = $pointer->contains('/foo/1');
34
35       Check if "data" contains a value that can be identified with the given
36       JSON Pointer.
37
38         # True
39         Mojo::JSON::Pointer->new('just a string')->contains('');
40         Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/♥');
41         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/foo');
42         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/1');
43
44         # False
45         Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/☃');
46         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/bar');
47         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/9');
48
49   get
50         my $value = $pointer->get('/foo/bar');
51
52       Extract value from "data" identified by the given JSON Pointer.
53
54         # "just a string"
55         Mojo::JSON::Pointer->new('just a string')->get('');
56
57         # "mojolicious"
58         Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->get('/♥');
59
60         # "bar"
61         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/foo');
62
63         # "4"
64         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/0');
65
66         # "6"
67         Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/2');
68
69   new
70         my $pointer = Mojo::JSON::Pointer->new;
71         my $pointer = Mojo::JSON::Pointer->new({foo => 'bar'});
72
73       Build new Mojo::JSON::Pointer object.
74

SEE ALSO

76       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
77
78
79
80perl v5.28.0                      2018-05-08            Mojo::JSON::Pointer(3)
Impressum