如何在Python中验证JSON模式架构?

时间:2012-12-11 01:18:05

标签: python jsonschema

我正在以编程方式生成JSON-Schema架构。我希望确保架构有效。是否有我可以验证我的架构的架构?

请注意我在该句和标题中使用了两次架构。我不想根据我的架构验证数据,我想验证我的架构。

1 个答案:

答案 0 :(得分:22)

使用jsonschema,您可以针对元架构验证架构。核心元架构是here,但jsonschema捆绑它,因此下载它是不必要的。

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)