栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

当接口返回的数据量大时如何比对 jsonschema

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

当接口返回的数据量大时如何比对 jsonschema

在线生成jsonschame
https://jsonschema.net/home
pip install jsonschema
from jsonschema import validate
def test_schame():
schame = {
“ s c h e m a " : " h t t p : / / j s o n − s c h e m a . o r g / d r a f t − 07 / s c h e m a " , " schema": "http://json-schema.org/draft-07/schema", " schema":"http://json−schema.org/draft−07/schema","id”: “http://example.com/example.json”,
“type”: “object”,
“required”: [
“productId”,
“productName”,
“price”,
“tags”
],
“properties”: {
“productId”: {
“$id”: “#/properties/productId”,
“type”: “integer”,
“title”: “The productId schema”,
“description”: “An explanation about the purpose of this instance.”,
“default”: 0,

    },
    "productName": {
        "$id": "#/properties/productName",
        "type": "string",
        "title": "The productName schema",
        "description": "An explanation about the purpose of this instance.",


    },
    "price": {
        "$id": "#/properties/price",
        "type": "number",

    },
    "tags": {
        "$id": "#/properties/tags",
        "type": "array",
        "additionalItems": True,
        "items": {
            "$id": "#/properties/tags/items",
            "anyOf": [
                {
                    "$id": "#/properties/tags/items/anyOf/0",
                    "type": "string",
                    "title": "The first anyOf schema",
                    "description": "An explanation about the purpose of this instance.",
                    "default": "",
                    "examples": [
                        "home",
                        "green"
                    ]
                }
            ]
        }
    }
},
"additionalProperties": True

}
test_data = {
“productId”: 1,
“productName”: “A green door”,
“price”: 12.50,
“tags”: [“home”, “green”]
}
validate(instance=test_data,schema=schame)

参考:https://blog.csdn.net/zbj18314469395/article/details/93721393

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/348534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号