Loading TOC...


   node as Node,
   schema as String,
   options as String[]
) as map:map


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

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


// 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-Report(node, "/schemas/example.json")
{"errors":["XDMP-JSVALIDATEINVTYPE: Invalid node type: Expected node of type text, found number at NumberNode(12) using schema \"/schemas/example.json\"", "XDMP-JSVALIDATEINVNODE: Invalid node: Node NumberNode(12) not valid against property 'items' expected {type: string, minLength: 1} using schema \"/schemas/example.json\"", "XDMP-JSVALIDATEINVNODE: Invalid node: Node ObjectNode({\"count\":3, \"items\":[12]}) not valid against property 'properties' expected {properties: {count:{...}, items:{...}}} 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.