学习 JSON Schema 的编写方式, 方便在使用 monaco 的时候对 编写的json数据做代码提示和规则检查. 同时也能方便以后在前后端统一数据检查规则. 引用: Understanding JSON Schema json-schema
概述
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents.
- Describes your existing data format(s).
- Provides clear human- and machine- readable documentation.
- Validates data which is useful for:
- Automated testing.
- Ensuring quality of client submitted data.
JSON Schema是一个词汇表,允许你注释和验证JSON文档。
- 描述现有的数据格式
- 提供清晰可供人和机器同时阅读的文档
- 对数据进行校验
- 自动化测试
- 确保用户输入数据的质量
下面是一个 JSON Schema 的样例:
- 数据 ```json { “name”: “George Washington”, “birthday”: “February 22, 1732”, “address”: “Mount Vernon, Virginia, United States” }
{ “first_name”: “George”, “last_name”: “Washington”, “birthday”: “1732-02-22”, “address”: { “street_address”: “3200 Mount Vernon Memorial Highway”, “city”: “Mount Vernon”, “state”: “Virginia”, “country”: “United States” } }
- **Schema**```json{"type": "object","properties": {"first_name": { "type": "string" },"last_name": { "type": "string" },"birthday": { "type": "string", "format": "date" },"address": {"type": "object","properties": {"street_address": { "type": "string" },"city": { "type": "string" },"state": { "type": "string" },"country": { "type" : "string" }}}}}
第一个结构不能验证通过, 而第二个可以.
