JavaScript:用于验证另一个 JSON 模式的 JSON 模式

Sed*_*Rey 3 javascript validation json jsonschema

我现在面临一个应用程序,它需要验证一个包含 JSON Schema 定义的表单。

我想知道JavaScript 上是否有validator schemafor JSONSchema

例如:

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);
Run Code Online (Sandbox Code Playgroud)

格式化的 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"]
}
Run Code Online (Sandbox Code Playgroud)

谢谢,

Iso*_*Iso 5

架构V4草案本身就是一个JSON模式您可以使用JSON架构的验证。