NAME
std/data/json/schema/relative_pointer - Relative JSON Pointer parser.
SYNOPSIS
from std/data/json/schema/relative_pointer import RelativeJSONPointer;
let doc := {
people: [
{ name: "Ada" },
{ name: "Grace" },
],
};
let pointer := new RelativeJSONPointer( path: "1/name" );
say( pointer.first( doc, "/people/0/age", "(missing)" ) );
IMPLEMENTATION SUPPORT
This Pure Zuzu module is supported by all implementations of ZuzuScript.
DESCRIPTION
Relative JSON Pointer describes a target by starting from a context location, climbing zero or more levels, optionally shifting an array index, and then optionally applying a normal JSON Pointer suffix. JSON Schema uses the syntax for the relative-json-pointer format.
This module evaluates relative pointers against a root document and a context pointer. The context pointer must itself be a JSON Pointer string.
EXPORTS
Classes
RelativeJSONPointerConstruct with
new RelativeJSONPointer( path: "0/foo" ). Invalid syntax throws during construction.Methods:
expression()Returns the original pointer expression.
up()Returns the number of levels the pointer climbs from the context location.
index_change()Returns the array-index offset, or
nullwhen none was supplied.pointer()Returns the JSON Pointer suffix, or
nullfor a#key request.key_request()Returns true for
#pointers that request the key or array index at the target location.target_pointer( context_pointer := "" )Returns the absolute JSON Pointer reached by climbing and applying any index offset, before the suffix is applied.
evaluate( root, context_pointer := "" )Evaluates the relative pointer. Normal pointers return the same array of matches as std/path/jsonpointer's
query.#key requests return the key or index string directly, ornullwhen the request names the document root.get( root, context_pointer := "" )Alias for
evaluate.first( root, context_pointer := "", fallback := null )Returns the first matched value, or
fallbackwhen no value is found. For#key requests,fallbackis returned only when the key request returnsnull.exists( root, context_pointer := "" )Returns true when evaluation finds a value. For
#key requests, the document root key is treated as absent.
Functions
valid_relative_json_pointer( text )Returns true when
textparses as a Relative JSON Pointer.
COPYRIGHT AND LICENCE
std/data/json/schema/relative_pointer is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.