Mojo::J...:Pointer(3)

πŸ’… Mojo::JSON::Pointer(3) β€” aka JSON Pointers, bestie

So this is the manual page for Mojo::JSON::Pointer, straight out of the User Contributed Perl Documentation section of your friendly local manpages. Yes, the page title is truncated to Mojo::J...:Pointer(3) because manpages are dramatic like that, but the real one is Mojo::JSON::Pointer. Slaaay. ✨


πŸ¦‹ NAME

Mojo::JSON::Pointer β€” literally just JSON Pointers, no cap.


🌸 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');

That's the whole vibe. Build a pointer-ish object over some data, then get stuff out of it with a path string, or contains to vibe-check whether a path even exists. 🫢


πŸŽ€ DESCRIPTION

Mojo::JSON::Pointer is an implementation of RFC 6901 <https://tools.ietf.org/html/rfc6901>. That's the spec, bestie β€” it's the whole personality of this module and it's iconic for it.


✨ ATTRIBUTES ✨

Mojo::JSON::Pointer implements the following attributes. Obsessed with how short this list is, honestly.

πŸ’– data

my $data = $pointer->data;
$pointer = $pointer->data({foo => 'bar'});

The data structure to be processed β€” like, the actual thing you're poking at with your pointers. Get it, set it, live your truth. 🌈


πŸ‘‘ METHODS πŸ‘‘

Mojo::JSON::Pointer inherits all methods from Mojo::Base and implements the following new ones. Main character energy only for the ones listed below.

πŸ“ contains

my $bool = $pointer->contains('/foo/1');

Check if data contains a value that can be identified with the given JSON Pointer. You get a boolean back. That's it, that's the whole method. πŸ’…

# True
Mojo::JSON::Pointer->new('just a string')->contains('');
Mojo::JSON::Pointer->new({'β™₯' => 'mojolicious'})->contains('/β™₯');
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/foo');
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/1');

# False
Mojo::JSON::Pointer->new({'β™₯' => 'mojolicious'})->contains('/β˜ƒ');
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/bar');
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/9');

Notice the '' empty pointer on a plain string is true β€” the whole scalar is the value, okay? And '/β˜ƒ'? Not in there. Snowman said no. 😭

🧚 get

my $value = $pointer->get('/foo/bar');

Extract a value from data identified by the given JSON Pointer. Fetched. Retrieved. Served. πŸ”₯

# "just a string"
Mojo::JSON::Pointer->new('just a string')->get('');

# "mojolicious"
Mojo::JSON::Pointer->new({'β™₯' => 'mojolicious'})->get('/β™₯');

# "bar"
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/foo');

# "4"
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/0');

# "6"
Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/2');

Array indexes start at 0, so /baz/0 gives you 4 and /baz/2 gives you 6. Counting from zero is so real of arrays, fr fr. πŸ¦‹

⭐ new

my $pointer = Mojo::JSON::Pointer->new;
my $pointer = Mojo::JSON::Pointer->new({foo => 'bar'});

Build a new Mojo::JSON::Pointer object. Pass it data or don't β€” either way you're valid. 🌸


🌟 SEE ALSO

Go read those, iykyk. πŸ’œ


πŸ’€ little reminder from your girl: the pointer strings are the whole API here. Get them wrong and contains will quietly hand you a false. No error, no drama, just vibes denied. Check your paths. πŸ™ˆ

That's the page, bestie! Signing off from perl v5.42.0, dated 2026-07-15, in the Mojo::J...:Pointer(3) section. Periodt. πŸ‘‘πŸŽ€

πŸ“¦ where this page comes from