I am trying to validate all rows in my JSON data file against the schema without looping through each data entry in the JSON file.
However when just passing in the entire JSON file no validation errors are returned. When looping through each row in the JSON file, the validation works as expected.
I included both validations, the first is how I'd like to validate but is not working as expected. The second validation works but I don't want to loop.
Python code:
import json
from jsonschema import validate
data = [
{
"Col1":"asd",
"Col2":"awer",
"Col3":"xyz"
},
{
"Col1":"asd",
"Col2":"awer",
"Col3":123
}
]
schema = {
"title": "test",
"properties":{
"Col1" : {
"minLength": 0,
"maxLength": 15,
"type": "string"
},
"Col2" : {
"minLength": 0,
"maxLength": 15,
"type": "string"
},
"Col3" : {
"minLength": 0,
"maxLength": 15,
"type": "string"
}
}
}
# Does not return an error
validate(instance=data, schema=schema)
# Works as expected
for i in range(0,2):
validate(instance=data[i], schema=schema)