This module implements the
QueryAdapter
interface to use the
JSON Pointer (RFC 6901)
query language as part of JM2MP projection documents.
This module only supports json-pointer 0.6.x versions. Other versions must be tested previously to be considered as well.
JSON Pointer is a standardized addressing syntax that identifies only single values within a JSON document using a string of tokens separated by the "/" (slash) character. It is not a general-purpose query language (it has no wildcards, filters, nor recursive descent), but it is covered by an RFC, and its grammar fits into thirty lines of notation.
Syntax based on RFC 6901:
""--> the root value (the full document)"/foo"--> "foo" property from the root object"/foo/0"--> first item in "foo" array"/a~1b"--> literal property "a/b" (~1 escapes '/')"/a~0b"--> literal property "a~b" (~0 escapes '~')"/-"--> the (nonexistent) member after the last array element (RFC 6901 §4)
By compliance with JM2MP, the
QueryAdapter
created by
createJsonPointerAdapter
maintains the expected behavior:
nullinput -->nulloutput without calling [JSONPath+external:JSONPath external library,- empty string as path --> root context (the full document),
- nonexistent path -->
null(avoiding any exception usinghasbeforeget), - a path always points to single scalar value --> returns such scalar value,
- syntax error --> raises an exception (ValidationError on validate and EvaluationError on evaluate).
The json-pointer library is dynamically loaded when constructing its corresponding QueryAdapter. If not previously installed, an AdapterError exception will be raised from createJsonPointerAdapter with a clear message about it.
Source
Methods
createJsonPointerAdapter() → {Promise.<module:jm2mp/adapters/registry.QueryAdapter>}
It creates a new QueryAdapter dynamically loading JSON Pointer version 0.6.x.
Returns
-
Promise.<module:jm2mp/adapters/registry.QueryAdapter>