# TypeError: Object of type UUID is not JSON serializable

- **ID:** `python/fastapi-json-encoding-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI's default JSON encoder cannot handle UUID objects in the response.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Use jsonable_encoder: from fastapi.encoders import jsonable_encoder; return jsonable_encoder(data)
   ```
2. **** (85% success)
   ```
   Define a custom response class that handles UUIDs: class UUIDModel(BaseModel): id: UUID
   ```

## Dead Ends

- **** — This is repetitive and error-prone if missed in some places. (60% fail)
- **** — If imported incorrectly, it may not convert UUIDs. (50% fail)
