Created
October 11, 2024 09:38
-
-
Save pinturic/20376d137c6ae563e92718a9703ae66b to your computer and use it in GitHub Desktop.
Avro validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fastavro | |
import json | |
# Load Avro schema | |
with open("schema.avsc", "r") as schema_file: | |
schema = json.load(schema_file) | |
# Load JSON data | |
with open("data.json", "r") as json_file: | |
json_data = json.load(json_file) | |
# Validate the JSON data against the Avro schema | |
try: | |
fastavro.validation.validate(json_data, schema) | |
print("JSON is valid against the Avro schema") | |
except fastavro.validation.ValidationError as e: | |
print("Validation failed:", e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment