| """Utilities for the json_fixes package.""" | |
| import re | |
| def extract_char_position(error_message: str) -> int: | |
| """Extract the character position from the JSONDecodeError message. | |
| Args: | |
| error_message (str): The error message from the JSONDecodeError | |
| exception. | |
| Returns: | |
| int: The character position. | |
| """ | |
| char_pattern = re.compile(r"\(char (\d+)\)") | |
| if match := char_pattern.search(error_message): | |
| return int(match[1]) | |
| else: | |
| raise ValueError("Character position not found in the error message.") | |