1

I am getting the following schema validation error using a JSON schema and valdictory as parser/validator. The schema has been autogenerated using jsonschema.net (using the same JSON data)

validictory.validator.FieldValidationError: Value '{"bp": [{"category": "bp", 
"created": "2013-03-08T09:14:48.148000", "value": 147.0, "day": "2013-03-11T00:00:00", 
 "value2": 43.0, "id": "dc049c0e-d19a-4e3e-93ea-66438a239712", "unit": "mmHg"}]}' 
 for field '_data' is not of type object

Code:

import json
import validictory

data = json.dumps({'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)

1 Answer 1

1

I'm not familiar with the library, but you appear to be validating the JSON text, not the data itself - so the validator is looking at a string, when the schema says the data should be an object.

What if instead of data = json.dumps({...}), you just had data = {...}?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.