# TypeError: Object of type datetime is not JSON serializable

- **ID:** `python/fastapi-jsonable-encoder-datetime`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Returning a raw datetime in a JSONResponse (not a Pydantic model) bypasses FastAPI's encoder; json.dumps cannot handle datetime.

## Version Compatibility

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

## Workarounds

1. **** (93% success)
   ```
   from fastapi.encoders import jsonable_encoder; return JSONResponse(jsonable_encoder(obj))
   ```
2. **** (90% success)
   ```
   Return a Pydantic model with datetime field; FastAPI serializes it
   ```

## Dead Ends

- **** — Easy to miss; inconsistent formats across endpoints. (50% fail)
- **** — Not interoperable with browsers and unsafe. (90% fail)
