Validate JSON data using python

前端 未结 3 1830
日久生厌
日久生厌 2021-01-03 06:42

I’m pretty new in python so would you be so kind to help me? It seems to be really trivial question. I need to create a function that validates incoming json data and return

3条回答
  •  走了就别回头了
    2021-01-03 07:33

    I had the same problem and was dissatisfied with the existing solution of using jsonschema. It gives terrible error messages that are not at all user-friendly.

    I wrote my own library to define schemas, which has a lot of additional functionality over jsonschema:

    https://github.com/FlorianDietz/syntaxTrees

    It gives very precise error messages, allows you to write code to customize the validation process, lets you define functions that operate on the validated JSON, and even creates HTML documentation for the schemas you define.

    Schemas are defined as classes, similar to how Django defines models:

    class MyExampleNode(syntaxTreesBasics.Node):
        field_1 = fields.Float(default=0)
        field_2 = fields.String()
        field_3 = fields.Value('my_example_node', null=True, default=None)
        class Meta:
            name = 'my_example_node'
    

提交回复
热议问题