Loading TOC...

MarkLogic 10 Product Documentation
xdmp:json-validate-report-node

xdmp:json-validate-report-node(
   $node as node(),
   $schema as node(),
   $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 validate-reportd.
schema A JSON schema node use for validatation.
options Validation options. Supported options:
"full"
Keep trying to find all the errors. (Default)
"strict"
Stop after the first error.

Example

  xdmp:json-validate-report-node(
     object-node{ "count": 3, "items": array-node{12} }, 
     object-node{
       "properties": object-node{
          "count": object-node{ "type":"integer", "minimum":0 },
          "items": object-node{ "type":"array", "items": object-node{"type":"string", "minLength":1 } }
        }
     })

=> 
<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 ""</error:format-string>
    <error:retryable>false</error:retryable>
    <error:expr/>
    <error:data>
      <error:datum>number-node{12}</error:datum>
      <error:datum>""</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 ""</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>""</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 ""</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>""</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.