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

时间:2016-07-18 12:19:33

标签: javascript json validation jsonschema

我现在正面临一个应用程序需要验证一个带有JSON Schema定义的表单。

我想知道JavaScript上的validator schema架构是否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"]
}

谢谢,

1 个答案:

答案 0 :(得分:4)

Schema Draft v4本身就是一个JSON Schema,可用于验证JSON Schema。