JSON Schema

http://json-schema.org/

关键字说明
typeJSON元素的数据类型,值必须是一个JSON对象
properties定义其下属性:定义各个键和它们的值类型,最小和最大值中要使用JSON文件
multipleOf数值实例有效反对“multipleOf”分工的实例此关键字的值,如果结果是一个整数。
maxLength字符串实例的长度被定义为字符的最大数目
minLength字符串实例的长度被定义为字符的最小数目
patternString实例被认为是有效的,如果正则表达式匹配成功实例
enum枚举项
$ref引用其他的schema
definitions内部结构体可被 $ref 引用
xxOf
not
{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "title":"xxx xx",
    "description":"xxxxx xxx xx",
    "type":"object",
    "properties":{
        "id":{
            "description":"The unique identifier for a book",
            "type":"integer",
            "minimum":1
        },
        "name":{
            "type":"string",
            "pattern":"^#([0-9a-fA-F]{6}$",
            "maxLength":6,
            "minLength":6
        },
        "price":{
            "type":"number",
            "multipleOf":0.5,
            "maximum":12.5,
            "exclusiveMaximum":true,
            "minimum":2.5,
            "exclusiveMinimum":true
        },
        "tags":{
            "type":"array",
            "items":[
                {
                    "type":"string",
                    "minLength":5
                },
                {
                    "type":"number",
                    "minimum":10
                }
            ],
            "additionalItems":{
                "type":"string",
                "minLength":2
            },
            "minItems":1,
            "maxItems":5,
            "uniqueItems":true
        }
    },
    "minProperties":1,
    "maxProperties":5,
    "required":[
        "id",
        "name",
        "price"
    ]
}

type: object

关键字说明
properties定义其下属性:定义各个键和它们的值类型,最小和最大值中要使用JSON文件
required必须属性
maxProperties最大属性个数
minProperties最小属性个数
patternProperties正则属性
additionalProperties未指定属性,即实际出现的额外属性

type: array

关键字说明
itemsarray 每个元素的类型 对象或对象数组
minItems约束属性,数组最小的元素个数
maxItems约束属性,数组最大的元素个数
additionalItemsitems 为数组时,对于多出部分的规定规则
uniqueItems元素唯一性

type: string

关键字说明
maxLength字符串的最大长度,>=0
minLength字符串的最小长度,>=0
pattern用正则表达式约束字符串,只有待校验JSON元素符合该关键字指定的正则表达式,才算通过校验
format字符串的格式 [ date-time(时间格式)、email(邮件格式)、hostname(网站地址格式)、ipv4、ipv6、uri、uri-reference、uri-template、json-pointer ]

type: integer or number

关键字说明
minimum最小值
maximum最大值
exclusiveMinimum是否严格大于minimum(不包含等于)
exclusiveMaximum是否严格小于maximum (不包含等于)
multipleOf是某数的倍数,值必须大于0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值