如何在Python中验证JSON模式架构? [英] How do I validate a JSON Schema schema, in Python?
本文介绍了如何在Python中验证JSON模式架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在以编程方式生成JSON-Schema模式.我希望确保该架构有效.有可以验证其架构的架构吗?
I am programmatically generating a JSON-Schema schema. I wish to ensure that the schema is valid. Is there a schema I can validate my schema against?
请注意我在该句子和标题中两次使用了模式.我不想根据自己的架构验证数据,而是想验证自己的架构.
Please note my use of schema twice in that sentence and the title. I don't want to validate data against my schema, I want to validate my schema.
推荐答案
使用 jsonschema ,您可以针对元架构验证模式.核心元模式位于此处,但是json模式将其捆绑在一起,因此无需下载.
Using jsonschema, you can validate a schema against the meta-schema. The core meta-schema is here, but jsonschema bundles it so downloading it is unnecessary.
from jsonschema import Draft3Validator
my_schema = json.loads(my_text_file) #or however else you end up with a dict of the schema
Draft3Validator.check_schema(my_schema)
这篇关于如何在Python中验证JSON模式架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文