JSON Schema详解
来源:互联网 发布:淘宝男装夏季 编辑:程序博客网 时间:2024/05/16 07:56
熟悉XML的开发人员都知道,对XML文档的定义有一个XML Schema。
同样,对于JSON文件的定义,也应该有一个JSON Schema以规范JSON文件内容。
JSON Schema用以标注和验证JSON文档的元数据的文档,可以类比于XML Schema。相对于JSON Schema,一个JSON文档就是JSON Schema的一个instance。
1.JSON Schema规范
IETF负责起草相关规范
最新版本是2017-4-15发布的Draft 6
http://json-schema.org/draft-06/schema
2. JSON Schema规范组成
- JSON Schema Core
- JSON Schema Validation
- JSON Hyper-Schema
1)Type-specific keywords
{ "type": "string", "pattern": "^(\\([0-9]{3}\\))?[0-9]{3}-[0-9]{4}$", "minLength": 2, "maxLength": 3, "format": "date-time|email|hostname|ipv4|ipv6|uri" }
{ "type": "number", "minimum": 0, "maximum": 100 }{ "type": "integer" }
{ "type": "object", "properties": { "name": { "type": "string" }, "credit_card": { "type": "number" } }, "required": ["name"] }
{ "type": "array", "minItems": 2, "maxItems": 3, "items": { "type": "number" } }
{ "type": "boolean" }
{ "type": "null" }
{ "type": ["number", "string"] }
2)Generic keywords
{ "title" : "Match anything", "description" : "This is a schema that matches anything.", "default" : "Default value"}
3)Combining schemas
- not
{ "not": { "type": "string" } }
- allOf
{ "allOf": [ { "type": "string" }, { "maxLength": 5 } ]}
- anyOf
{ "anyOf": [ { "type": "string", "maxLength": 5 }, { "type": "number", "minimum": 0 } ]}
- oneOf
{ "oneOf": [ { "type": "number", "multipleOf": 5 }, { "type": "number", "multipleOf": 3 } ]}
4)$schema keyword
"$schema": "http://json-schema.org/schema#"
"$schema": "http://json-schema.org/draft-06/schema#"
5)Regular Expressions
6)$ref keyword
- 基本复用
{ "$ref": "#/currentdoc/definitions/address" }
或
{ "$ref": "asidedoc_definitions.json#/address" }
- id设置基本URI
{ "$ref": "person.json" }
- 扩展复用
"shipping_address": { "allOf": [ // Here, we include our "core" address schema... { "$ref": "#/definitions/address" }, // ...and then extend it with stuff specific to a shipping // address { "properties": { "type": { "enum": [ "residential", "business" ] } }, "required": ["type"] } ]}
4. 解析软件
- Java
https://github.com/java-json-tools/json-schema-validator
https://github.com/networknt/json-schema-validator
- Python
https://github.com/zyga/json-schema-validator
- Online
参考链接:
http://json-schema.org/
阅读全文
1 0
- JSON Schema详解
- Json schema
- json schema
- json schema
- JSON Schema
- Json Schema
- RAML 0.8中引用JSON Schema的方法详解
- RAML 1.0中引用JSON Schema的方法详解
- 详解Schema
- schema详解
- JSON Schema(官方)
- JSON-Schema学习心得
- Json schema规范写法
- JSON 模式(Schema)
- JSON- 框架模式(Schema)
- JSON Schema Validator
- JSON schema简介
- json-schema-core(liuhailong翻译)
- CSDN修改资源分数值,取消0分,最低分为1分
- Junit的使用实例
- CentOS7利用pip快速安装TensorFlow
- VS VC 编译调试比特币源码
- heartbeat高可用详解
- JSON Schema详解
- tensorflow常用函数及概念
- 如何自己做lenet样本,使用LMDB格式
- CSS3的calc()做响应模式布局
- Maven标签解释
- C# 只开启一个程序,如果第二次打开则自动将第一个程序显示到桌面
- Wifi 控制
- Unity 5着色器系统代码介绍(上)
- 资讯精选 | 如何保证人工智能与HPC的成功融合?