Name
cx:jsonpath — Queries a JSON document with JSONPath.
Synopsis
This step evaluates JSONPath (RFC 9535) queries against JSON documents. The query result is returned.
Input port | Primary | Sequence | Content types |
---|---|---|---|
source | ✔ | json |
Output port | Primary | Sequence | Content types |
---|---|---|---|
result | ✔ | json |
Option name | Type | Default value | Required |
---|---|---|---|
query | xs:string | ✔ | |
parameters | map(xs:QName, item()*)? | () |
<p:import href="https://xmlcalabash.com/ext/library/jsonpath.xpl"/>
Declaration
1 |<p:declare-step xmlns:p="http://www.w3.org/ns/xproc">
| <p:input port="source" content-types="json"/>
| <p:output port="result" content-types="json"/>
| <p:option name="query" as="xs:string" required="true"/>
5 | <p:option name="parameters" as="map(xs:QName, item()*)?"/>
|</p:declare-step>
Errors
Code | Description |
---|---|
cxerr:XC0037 | It is a dynamic error (cxerr:XC0037 ) if the parameter
provided has an unrecognized name. |
cxerr:XC0039 | It is a dynamic error (cxerr:XC0039 ) if the JSONPath
expression is invalid. |
Description
The query
provided is evaluated against the source
document. The resulting JSON is returned on the result port. This step
uses version 2.9.0 of the
com.jayway.jsonpath
implementation of JSONPath.
It is a dynamic error (cxerr:XC0039
) if the JSONPath
expression is invalid.
The parameters show in Table 1, “JSONPath options” are supported. A parameter is enabled if its effective boolean value is true.
Parameter | Explanation |
---|---|
as-path-list | Return paths instead of values |
default-path-leaf-to-null | Return null for missing leaves |
always-return-list | Return a list even when the path is definite |
suppress-exceptions | Return an empty list or null instead of raising an error |
require-properties | Requires properties in an indefinite path |
It is a dynamic error (cxerr:XC0037
) if the parameter
provided has an unrecognized name.
Dependencies
This step is included in the XML Calabash application. If you are getting XML Calabash from Maven, you will also need to include the extension dependencies:
com.jayway.jsonpath:json-path:2.9.0
net.minidev:json-smart:2.5.1