Load a UTF-8 JSON document with clear errors for invalid or missing files.
import json
from pathlib import Path
def load_json(path: str):
try:
return json.loads(Path(path).read_text(encoding='utf-8'))
except (OSError, json.JSONDecodeError) as error:
raise ValueError(f'Cannot read {path}: {error}') from error