python的json模式验证的一个实现,分叉以避免依赖性问题
jsonschemanlplab的Python项目详细描述
这是一个https://github.com/Julian/jsonschema的叉,它仅用于规避依赖性不兼容。
jsonschemanlplab是JSON Schema的实现 对于python(支持2.7+包括python 3)。
>>>fromjsonschemanlplabimportvalidate>>># A sample schema, like what we'd get from json.load()>>>schema={..."type":"object",..."properties":{..."price":{"type":"number"},..."name":{"type":"string"},...},...}>>># If no exception is raised by validate(), the instance is valid.>>>validate(instance={"name":"Eggs","price":34.99},schema=schema)>>>validate(...instance={"name":"Eggs","price":"Invalid"},schema=schema,...)# doctest: +IGNORE_EXCEPTION_DETAILTraceback(mostrecentcalllast):...ValidationError:'Invalid'isnotoftype'number'
也可以从控制台使用:
$ jsonschemanlplab -i sample.json sample.schema
功能
- 全力支持 Draft 7, Draft 6, Draft 4 和 Draft 3
- Lazy validation 它可以反复报告all验证错误。
- Programmatic querying 验证失败的属性或项。
发行说明
版本3.0支持草案7(和6)。重新定义的接口 还对类型进行了主要的检查,以支持对 验证程序将接受或允许的类型。
jsonschemanlplab现在也通过appveyor在windows下测试。
感谢所有一路上提出请求的人。
运行测试套件
如果您安装了tox(可能通过pip install tox或 包管理器),在源目录中运行tox。 签出将在所有版本上运行jsonschemanlplab的测试套件 python的jsonschemanlplab支持。如果你没有所有的 在jsonschemanlplab下测试的版本,您可能希望运行 使用tox的--skip-missing-interpreters选项。
当然,您也可以使用 最喜欢的测试运行程序。测试存在于jsonschemanlplab.tests包中。
基准
jsonschemanlplab的基准使用perf。
运行它们可以通过tox -e perf或通过调用perf 外部命令(在确保它和jsonschemanlplab本身都是 已安装):
$ python -m perf jsonschemanlplab/benchmarks/test_suite.py --hist --output results.json
要与上一次运行进行比较,请使用:
$ python -m perf compare_to --table reference.json results.json
有关详细信息,请参阅perf文档。
贡献
我是朱利安·伯曼。
jsonschema在GitHub上。
通过Github或其他方式联系,如果你有什么要贡献的, 非常欢迎!
你也可以在freenode(nick:tos9)上找到我 频道,包括#python。
如果你非常感激,你可以通过 谷歌支付与我的github配置文件的电子邮件。