{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "integer"
},
"name": {
"description": "Name of the product",
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
}
},
"required": ["id", "name", "price"]}
json schema 校验json字符串是否满足要求,则是通过校验关键字去校验,如required,是否必需,maxItems用于校验数组的大小等,详细请见https://datatracker.ietf.org。所以我们要创建好json schema才能根据要求去校验数据,https://jsonschema.net/#/editor可用于生成json schema不过因google被墙可能无法正常使用,亦可搜索其它生成工具。