Created
February 28, 2025 14:41
-
-
Save swabb/0f1b315696d12558693a1698eccdcbd7 to your computer and use it in GitHub Desktop.
YAML file with JSONSchema validating
This file contains hidden or 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 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