How to read a JSON file and validate the response against the schema.
Install the following requirements:
- pip install jsonschema
Use the below code to read a JSON:
def readJSONFile(fileName):
data = open(fileName)
jsonData = json.load(data)
return jsonData
Use the below code to validate a JSON schema:
def validate_schema(json_data, json_schema):
try:
validate(instance=json_data, schema= json_schema)
except jsonschema.exceptions.ValidationError as err:
assert False, "JSON schema is not matching, Please check"
No comments:
Post a Comment