Option 3: One-liner
data = json.load(open('data.json', encoding='utf-8')) ```
3. Complete Example with Error Handling
```python import json from pathlib import Path from typing import Any
def read_json(file_path: str | Path) -> Any: """Safely read a JSON file with proper error handling.""" try: path = Path(file_path) with open(path, 'r', encoding='utf-8') as file: return json.load(file)
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
return None
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in '{file_path}': {e}")
return None
except Exception as e:
print(f"Unexpected error reading '{file_path}': {e}")
return None
