Spaces:
Sleeping
Sleeping
File size: 1,091 Bytes
5eaaba5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import json
from jsonschema import validate, exceptions
meta_schema = {
"type": "object",
"required": ["type", "properties"],
"properties": {"type": {"type": "string"}, "properties": {"type": "object"}},
}
def validate_schema_structure(schema_str):
"""
Parse and Validate a JSON Schema object
Args:
schema_str: A valid JSON schema object seralized to a string
Returns:
tuple: (bool, object) where:
- First element is a boolean indicating success (True) or failure (False)
- Second element is either the validated schema object (on success)
or an error message string (on failure)
"""
try:
schema = json.loads(schema_str)
validate(instance=schema, schema=meta_schema)
return True, schema
except exceptions.ValidationError as e:
return False, f"Schema structure validation error: {e}"
except json.JSONDecodeError as e:
return False, f"Invalid JSON syntax: {str(e)}"
except Exception as e:
return False, f"Unexpected error: {str(e)}"
|