NAME
std/path/jsonpointer - RFC 6901 JSON Pointer selectors.
SYNOPSIS
from std/path/jsonpointer import JSONPointer;
let data := {
users: [
{ name: "Ada" },
{ name: "Bob" },
],
};
let pointer := new JSONPointer( path: "/users/0/name" );
say( pointer.first(data) );
IMPLEMENTATION SUPPORT
This module is supported by all implementations of ZuzuScript.
DESCRIPTION
JSONPointer implements JSON Pointer as defined by RFC 6901. It provides the same path API shape as std/path/simple and std/path/z: get, select, query, first, exists, assignment methods, reference methods, and lexical path-operator registration via use.
Syntactically valid pointers that do not resolve return no matches for read APIs.
EXPORTS
Classes
JSONPointer({ path: String })Constructs a JSON Pointer selector. Returns:
JSONPointer.JSONPointer.use()Parameters: none. Returns:
null. Makes this path class the lexical implementation for@,@@, and@?.pointer.expression()Parameters: none. Returns:
String. Returns the original pointer expression.pointer.get(value),pointer.select(value),pointer.query(value)Parameters:
valueis the query root. Returns:Array. Evaluates the pointer and returns selected values.pointer.first(value, fallback?)Parameters:
valueis the query root andfallbackis optional. Returns: value. Returns the selected value, orfallback/nullwhen there is no match.pointer.exists(value)Parameters:
valueis the query root. Returns:Boolean. Returns true when the pointer resolves to a concrete value.pointer.assign_first(target, value, op := ":=", weak := false)Parameters:
targetis the query root,valueis the assignment value,opis an assignment operator, andweakis accepted for path API compatibility. Returns: value. Updates the selected location.pointer.assign_all(target, value, op := ":=", weak := false)Parameters: same as
assign_first. Returns: value. Updates the selected location when it exists.pointer.assign_maybe(target, value, op := ":=", weak := false)Parameters: same as
assign_first. Returns:Boolean. Updates the selected location when it exists.pointer.ref_first(target)Parameters:
targetis the query root. Returns:Function. Returns a reference-like getter/setter for the selected location.pointer.ref_all(target)Parameters:
targetis the query root. Returns:Array. Returns a single reference-like getter/setter when the pointer resolves, otherwise an empty array.pointer.ref_maybe(target)Parameters:
targetis the query root. Returns:Functionornull. Returns a reference-like getter/setter when the pointer resolves.
Functions
extract_pointer_from_url(url)Parameters:
urlis aString. Returns:Dict. Splits a URL intobaseurlandpointer. If the URL contains#,baseurlis the text before#andpointeris the URI-fragment percent-decoded JSON Pointer. If the URL has no#,baseurlis the full URL andpointerisnull.
SEE ALSO
Specification: https://www.rfc-editor.org/rfc/rfc6901.
COPYRIGHT AND LICENCE
std/path/jsonpointer 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.