{
"id": 1,
"name": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}
这里可以看到有文档遵循的协议格式,标题,描述以及文档的类型
{
"$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//排除掉最小值,不允许为0
},
"tags": {
"type": "array",//数据的类型是数组
"items": {//数组里每个item都是字符串
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"required": ["id", "name"]
完成表单数据校验,数据类型,格式定义和实际dom分离 schema
var validation = schema.validate({
q: 'OK',
start: -5,
num: -100.99,
xyz: 'additionalProperty'
})
未压缩情况下面加起来不到20kb,压缩体积会更小,适合数据校验
直出后这里node后台层应该是需要一个强类型的结构来定义协议,jsonschema是个不错的选择
jsonschema.net 使用者自己书写数据,框架根据数据生成格式
demo 目前仅支持jade语法。。。。
相关文档可参考这里
方便书写jsonschema格式 vm工具 json schema lint 一个在线的格式检验工具,可以作为插件集成到构建中去