JSON-Schema-Modern
view release on metacpan or search on metacpan
lib/JSON/Schema/Modern/Utilities.pm view on Meta::CPAN
# the first argument is an already-encoded json pointer; remaining arguments are path segments to be
# encoded and appended
sub jsonp {
carp q{first argument to jsonp should be '' or start with '/'} if length($_[0]) and substr($_[0],0,1) ne '/';
return join('/', shift, map s!~!~0!gr =~ s!/!~1!gr, grep defined, @_);
}
# splits a json pointer apart into its path segments
sub unjsonp {
carp q{argument to unjsonp should be '' or start with '/'} if length($_[0]) and substr($_[0],0,1) ne '/';
return map s!~0!~!gr =~ s!~1!/!gr, split m!/!, $_[0];
}
sub jsonp_get ($data, $pointer) {
Mojo::JSON::Pointer->new($data)->get($pointer);
}
# flatten the data structure into a hashref of { pointer => value, ... }
# (essentially the reverse of jsonp_set($data, $foo->%{$_}) foreach keys $foo)
sub jsonp_elements ($data, $prefix = '') {
# recursively walk the structure..
( run in 1.200 second using v1.01-cache-2.11-cpan-71847e10f99 )