Loading TOC...

MarkLogic Server 11.0 Product Documentation
xdmp:json-validate-report

xdmp:json-validate-report(
   $node as node(),
   $schema as xs:string,
   $options as xs:string*
) as element(xdmp:validation-errors)

Summary

Validate a JSON node against a JSON Schema and return an error report.

Parameters
node JSON node to be validated.
schema URI of the JSON schema to use for validation.
options Validation options. Supported options:
"full"
Keep trying to find all the errors. (Default)
"strict"
Stop after the first error.

Example

(: Assuming the following JSON schema is in the schema database at
   "/schemas/example.json" :
    {
      "language": "zxx",
      "$schema": "http://json-schema.org/draft-07/schema#",
      "properties": {
         "count": { "type":"integer", "minimum":0 },
         "items": { "type":"array", "items": {"type":"string", "minLength":1 } }
      }
    }
:)
  xdmp:json-validate-report(
     object-node{ "count": 3, "items": array-node{12} }, "/schemas/example.json" )

=> 
<xdmp:validation-errors xmlns:xdmp="http://marklogic.com/xdmp">
<error:error xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <error:code>XDMP-JSVALIDATEINVTYPE</error:code>
    <error:name/>
    <error:xquery-version>1.0-ml</error:xquery-version>
    <error:message>Invalid node type</error:message>
    <error:format-string>XDMP-JSVALIDATEINVTYPE: Invalid node type: Expected node of type text, found number at number-node{12} using schema "/schemas/example.json"</error:format-string>
    <error:retryable>false</error:retryable>
    <error:expr/>
    <error:data>
      <error:datum>number-node{12}</error:datum>
      <error:datum>"/schemas/example.json"</error:datum>
      <error:datum>text</error:datum>
      <error:datum>number</error:datum>
    </error:data>
    <error:stack>
      <error:frame>
	<error:line>2</error:line>
	<error:column>2</error:column>
	<error:xquery-version>1.0-ml</error:xquery-version>
      </error:frame>
    </error:stack>
  </error:error>
  <error:error xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <error:code>XDMP-JSVALIDATEINVNODE</error:code>
    <error:name/>
    <error:xquery-version>1.0-ml</error:xquery-version>
    <error:message>Invalid node</error:message>
    <error:format-string>XDMP-JSVALIDATEINVNODE: Invalid node: Node number-node{12} not valid against property 'items' expected {type: string, minLength: 1} using schema "/schemas/example.json"</error:format-string>
    <error:retryable>false</error:retryable>
    <error:expr/>
    <error:data>
      <error:datum>items</error:datum>
      <error:datum>number-node{12}</error:datum>
      <error:datum>"/schemas/example.json"</error:datum>
      <error:datum>{type: string, minLength: 1}</error:datum>
    </error:data>
    <error:stack>
      <error:frame>
	<error:line>2</error:line>
	<error:column>2</error:column>
	<error:xquery-version>1.0-ml</error:xquery-version>
      </error:frame>
    </error:stack>
  </error:error>
  <error:error xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <error:code>XDMP-JSVALIDATEINVNODE</error:code>
    <error:name/>
    <error:xquery-version>1.0-ml</error:xquery-version>
    <error:message>Invalid node</error:message>
    <error:format-string>XDMP-JSVALIDATEINVNODE: Invalid node: Node object-node{"count":number-node{3}, "items":array-node{number-node{12}}} not valid against property 'properties' expected {properties: {count:{...}, items:{...}}} using schema "/schemas/example.json"</error:format-string>
    <error:retryable>false</error:retryable>
    <error:expr/>
    <error:data>
      <error:datum>properties</error:datum>
      <error:datum>object-node{"count":number-node{3}, "items":array-node{number-node{12}}}</error:datum>
      <error:datum>"/schemas/example.json"</error:datum>
      <error:datum>{properties: {count:{...}, items:{...}}}</error:datum>
    </error:data>
    <error:stack>
      <error:frame>
	<error:line>2</error:line>
	<error:column>2</error:column>
	<error:xquery-version>1.0-ml</error:xquery-version>
      </error:frame>
    </error:stack>
  </error:error>
</xdmp:validation-errors>
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.