import json import jsonschema schema = { "$schema": "http://json-schema.org/schema#", "type": "object", "properties": { "document_version": { "type": "integer" }, "ip": { "type": "string" }, "port": { "type": "integer" }, "whois_description": { "type": "string" }, "asn": { "type": "string" }, "asn_country_code": { "type": "string" }, "ptr": { "type": "string" }, "abuse_mail": { "type": "string" }, "domain": { "type": "string" }, "timestamp_in_utc": { "type": "string" }, "user_presentation": { "type": "object", "properties": { "description": { "type": "string" }, "data": { "type": "object" } } } }, "required": [ "document_version", "ip", "port", "timestamp_in_utc", "user_presentation" ] } def validate_collector_data(json_blob): try: jsonschema.validate(json_blob, schema) except jsonschema.exceptions.ValidationError as e: print(f'Validation failed with error: {e}') return False return True if __name__ == '__main__': with open('example_data.json') as fd: json_data = json.loads(fd.read()) validate_collector_data(json_data)