type关键字是JSON模式的基础。它指定模式的数据类型。
object
{ "type": "object" }
{
"key": "value"
}
{
1: "123"
}
"123"
properties
列出的其他的属性,默认允许其他属性,如果为对象,则该对象是将用于验证未在中列出的任何其他属性的架构properties。{ "type": "object", "properties": { "name": "string", "age": "number" }, "additionalProperties": false }
{ "type": "object", "properties": { "name": "string", "age": "number" }, "additionalProperties": { "type": "string" } }
{ "type": "object", "properties": { "age": { "type": "number" }, "name": { "type": "string" }, "gender": "string" }, "dependencies": { "name": ["gender"] } } // success { "age": 123, "name": "123", "gender": "women" } // error 缺少gender { "age": 123, "name": "123" }
{ "type": "object", "properties": { "age": { "type": "number" }, "name": { "type": "string" } }, "dependencies": { "name": { "properties": { "gender": { "type": "string" } }, "required": ["gender"] } } } // success { "age": 123, "name": "123", "gender": "women" }
{ "type": "array", "items": [ { "type": "number" }, { "type": "string" }, { "type": "string", "enum": ["Street", "Avenue", "Boulevard"] }, { "type": "string", "enum": ["NW", "NE", "SW", "SE"] } ], "additionalItems": false } --- // success [1600, "Pennsylvania", "Avenue", "NW"] // error [1600, "Pennsylvania", "Avenue", "NW", "Washington"]
{ "type": "array", "items": [ { "type": "number" }, { "type": "string" }, { "type": "string", "enum": ["Street", "Avenue", "Boulevard"] }, { "type": "string", "enum": ["NW", "NE", "SW", "SE"] } ], "additionalItems": { "type": "string" } } --- // success [1600, "Pennsylvania", "Avenue", "NW", "Washington"] // error [1600, "Pennsylvania", "Avenue", "NW", 20500]
"date-time"
:2018-11-13T20:20:39+00:00。"time"
:20:20:39+00:00"date"
:2018-11-13。"email"
: 互联网电子邮箱"idn-email"
:Internet电子邮箱地址的国际化形式"hostname"
:互联网主机名"idn-hostname"
:国际化internet主机名"uri"
"uri-reference"
"iri"
"iri-reference"
"uri-template"
"json-pointer"
"relative-json-pointer"