如何测试和检查JSON文件并报告错误
我当前正在使用JSonschema
python
检查我的JSON文件。我创建了一个schema.json
检查已循环的JSON文件,并且根据我在schema.json 。 目前,我无法在正在检查的JSON文件中显示和突出显示错误,例如,
"data_type": {
"type": "string",
"not": { "enum": ["null", "0", "NULL", ""] }
},
如果JSON文件具有值“ data_type”:“ nenull”
或Eneum中类似的内容,它将显示json文件无效
,但我希望它突出显示错误并显示您在data_type字段中添加了null
我可以使用jsonschema做到吗?
如果没有使用jsonschema
的另一种方式,则可以使用;主要测试是在文件夹中检查多个JSON文件(可以循环循环),并根据几组规则检查它们是否有效,并显示一个干净且不错的报告,该报告专门告诉我们问题。
I am currently using jsonschema
with python
to check my json files. I have created a schema.json
that checks the json files that are looped over, and I display the file is invalid or valid according to the checks i have added in my schema.json
.
Currently i am not able to display and highlight the error in the json file which is being checked, for example
"data_type": {
"type": "string",
"not": { "enum": ["null", "0", "NULL", ""] }
},
if the json file has the value "data_type" : "null"
or anything similar in the enum, it will display json file is invalid
but i want it to highlight the error and display you added null in the data_type field
can i do it with jsonschema?
If there is another way without using jsonschema
that will work; the main testing is to check multiple json files in a folder (which can be looped over) and check whether they are valid according to few set of rules and display a clean and nice report which specifically tells us the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我所做的是从
jsonschema
中使用的draft7validator
,它允许显示错误消息此打印 -
有用的链接,它帮助我实现了this- 处理验证错误
What I did is used
Draft7Validator
fromjsonschema
and it allows to display error messageThis prints -
Helpful link that helped me achieve this- Handling Validation Errors