JavaScript:JSON模式以验证另一个JSON模式

我现在正面临一个应用程序,该应用程序需要使用内部的JSON Schema定义来验证表单.

我想知道JavaScript上是否有用于JSON模式的验证器模式

例如:

let validate = schemaValidator.validate('{"title": "Example Schema","type": "object","properties": {"firstName": {"type": "string"},"lastName": {"type": "string"},"age": {"description": "Age in years","type": "integer","minimum": 0}},"required": ["firstName", "lastName"]}', metaSchema);

格式化的JSON

{
  "title": "Example Schema",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["firstName", "lastName"]
}

谢谢,

解决方法:

Schema Draft v4本身是一个JSON模式,可用于验证JSON模式.

上一篇:NTT


下一篇:FHQ简要笔记