Skip to content

Instantly share code, notes, and snippets.

@pinturic
Created October 11, 2024 09:38
Show Gist options
  • Save pinturic/20376d137c6ae563e92718a9703ae66b to your computer and use it in GitHub Desktop.
Save pinturic/20376d137c6ae563e92718a9703ae66b to your computer and use it in GitHub Desktop.
Avro validation
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