
xdmp.jsonValidateReport( 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.
// 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: Get the most useful answers to questions from the MarkLogic community, or ask your own question.