I am using validictory for validating the attached JSON data and schema. Working so far.
However the data dictionary can have arbitrary string keys (others than 'bp' but). The key 'bp' in the schema here is hard-coded...it can be a string from a given list (enum of string). How do I add the enum definition here for the "first level" of the dict.
import json
import validictory
data = {'bp': [{'category': 'bp',
'created': '2013-03-08T09:14:48.148000',
'day': '2013-03-11T00:00:00',
'id': 'dc049c0e-d19a-4e3e-93ea-66438a239712',
'unit': 'mmHg',
'value': 147.0,
'value2': 43.0}]}
schema = {
"type":"object",
"properties":{
"bp": {
"type":"array",
"required":False,
"items":
{
"type":"object",
"required":False,
"properties":{
"category": {
"type":"string",
"default": "bp",
"required":False
},
"created": {
"type":"string",
"default": "2013-03-08T09:14:48.148000",
"required":False
},
"day": {
"type":"string",
"default": "2013-03-11T00:00:00",
"required":False
},
"id": {
"type":"string",
"default": "dc049c0e-d19a-4e3e-93ea-66438a239712",
"required":False
},
"unit": {
"type":"string",
"default": "mmHg",
"required":False
},
"value2": {
"type":"number",
"default":43,
"required":False
},
"value": {
"type":"number",
"default":147,
"required":False
}
}
}
}
}
}
validictory.validate(data,schema)