I am writing a Python code to validate JSON schema but it is not showing all the errors in it , only the first one. Can anyone help to fix the code so that it displays all the errors. Below is the code:
from __future__ import print_function
import sys
import json
import jsonschema
from jsonschema import validate
schema = {
"type" : "object",
"properties" : {
"price" : {"type" : "number"},
"name" : {"type" : "string"},
},
}
data = \
[
{ "name": 20, "price": 10},
]
print("Validating the input data using jsonschema:")
for idx, item in enumerate(data):
try:
validate(item, schema)
sys.stdout.write("Record #{}: OK\n".format(idx))
except jsonschema.exceptions.ValidationError as ve:
sys.stderr.write("Record #{}: ERROR\n".format(idx))
sys.stderr.write(str(ve) + "\n")