Usage (2)

data = read_json('data.json') print(data)


### Method 2: Simple version (most common)

```python
import json

with open('data.json', 'r', encoding='utf-8') as file:
    data = json.load(file)

print(data)

Complete Example

```python import json from pathlib import Path from typing import Any

def load_json(file_path: str | Path) -> dict | list: """Safely load a JSON file.""" try: path = Path(file_path) with path.open('r', encoding='utf-8') as file: return json.load(file) except FileNotFoundError: print(f"Error: File '{file_path}' not found.") return {} except json.JSONDecodeError as e: print(f"Error: Invalid JSON in '{file_path}': {e}") return {} except Exception as e: print(f"Unexpected error: {e}") return {}