JSONSchema is way of defining what shape your desired JSON should have and what certain fields type and content should be.
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents.
project’s webiste: http://json-schema.org/
in python project you can use this pip installed package https://pypi.python.org/pypi/jsonschema
Defining list of basic types vs list of objects
You define list of basic types, like e.g
"hobbys" in employee just by defining
while if you need to define list of certain shape objects you have to define
"type": "object" and define
"type" of each
More options to validate:
- each of field can be in
requiredlist to make it obligatory
- for lists you can define
minItemsto control allowed number of objects.
- for ensuring list object uniqness just provide
"uniqueItems": truethis works only on basic data types (not on objects)
- you can validate strings with regex by using
patternlike in above example for valid date in
- tuple validation may be something nice for structured data types https://spacetelescope.github.io/understanding-json-schema/reference/array.html#tuple-validation
Usefull links of docs with greate examples: