You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MarkLogic10运行xdmp.jsonValidate报XDMP-JSVALIDATEBADSCHEMA错误求助

问题原因总结

1. JSON Schema存在语法错误(不符合标准JSON规范)

标准JSON不允许任意位置出现尾随逗号,你的schema中有两处非法尾随逗号:

  • LastUpdatedDt属性定义结束后的多余逗号
  • required数组最后一个元素后的多余逗号
    MarkLogic解析JSON schema时会直接将存在语法错误的JSON判定为无效。

2. JSON Schema结构不符合Draft 07规范

你把required字段错误嵌套在了properties对象内部,按照JSON Schema Draft 07的规范,required是和properties平级的顶层规则字段,用于声明当前对象下必须存在的属性,嵌套在properties中会被识别为普通的属性定义,无法起到必填校验的作用,同时也不符合MarkLogic对JSON Schema的结构要求。

3. 校验代码的参数调用错误

xdmp.jsonValidate的第二个参数支持传入schema文档节点、schema对象或者schema的字符串内容,你调用cts.doc('/schemas/NewSchema.json').toString()时,实际输出的是节点对象的序列化标识(并非schema的JSON文本内容),传入无效的内容会触发XDMP-JSVALIDATEBADSCHEMA错误。
另外需要确认/schemas/NewSchema.json是保存在对应MarkLogic Schemas数据库中,且当前查询用户有该文档的读取权限。


修复后的参考内容

修正后的JSON Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "SourceSystemName": {
        "type": "string"
    },
    "BatchDtTm": {
        "type": "string"
    },
    "SubjectArea": {
        "type": "string"
    },
    "DocumentType": {
        "type": "string"
    },
    "LastUpdatedDt": {
        "type": "string"
    }
  },
  "required": [
    "SourceSystemName",
    "BatchDtTm",
    "SubjectArea",
    "DocumentType",
    "LastUpdatedDt"
  ]
}

修正后的查询代码

let jsonRecord = {"SourceSystemName":"ODH","BatchDtTm":"09/17/21 08:51:48:472723","SubjectArea":"Customer","DocumentType":"Preference","LastUpdatedDt":"09/17/21 03:59:53:629707"};
// 直接传入schema文档节点即可,不需要调用toString()
xdmp.jsonValidate(jsonRecord, cts.doc('/schemas/NewSchema.json'));

内容的提问来源于stack exchange,提问作者Hank

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 20:57:02