Skip to content

Instantly share code, notes, and snippets.

@swabb
Created February 28, 2025 14:41
Show Gist options
  • Save swabb/0f1b315696d12558693a1698eccdcbd7 to your computer and use it in GitHub Desktop.
Save swabb/0f1b315696d12558693a1698eccdcbd7 to your computer and use it in GitHub Desktop.
YAML file with JSONSchema validating
import yaml
import json
from jsonschema import validate, ValidationError
with open('values.yaml', 'r') as yaml_file:
yaml_content = yaml.safe_load(yaml_file)
json_content = json.dumps(yaml_content)
print(json_content)
with open('values.schema.json', 'r') as schema_file:
schema = json.load(schema_file)
try:
validate(instance=json_content, schema=schema)
print("YAML file is valid.")
except ValidationError as e:
print(f"Validation error: {e.message}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment