Loading TOC...

MarkLogic 12 EA 2 Product Documentation
xdmp.jsonValidateReport

xdmp.jsonValidateReport(
   node as Node,
   schema as String,
   options as String[]
) as map:map

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 } }
//    }
//  }
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.