Loading TOC...

MarkLogic 10 Product Documentation
xdmp.jsonValidate

xdmp.jsonValidate(
   node as Node,
   schema as String,
   options as String[]
) as Node

Summary

Validate a JSON node against a JSON Schema. If the node is not valid per the schema, raise an error. Otherwise, return the input node.

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.
"strict"
Stop after the first error. (Default)

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 } }
//    }
//  }
var node = {"count":3, "items": [12]}; 
xdmp.jsonValidate(node, "/schemas/example.json")
=>
XDMP-JSVALIDATEINVTYPE: xdmp.jsonValidate(node, "/schemas/example.json") -- Invalid node type: Expected node of type text, found number at NumberNode(12) using schema "/schemas/example.json"

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