in devai-cli/src/devai/commands/review.py [0:0]
def validate_and_correct_json(json_text):
"""Validates and attempts to correct JSON text.
Args:
json_text (str): The JSON text to validate.
Returns:
str: The original or corrected JSON text if valid, None otherwise.
"""
try:
# Validate the JSON
json.loads(json_text)
return json_text # JSON is already valid
except json.JSONDecodeError:
try:
# If invalid, attempt to repair
return repair_json(json_text)
except ValueError:
click.echo(
"Error: Model output is not valid JSON and could not be repaired."
)
return None