# TypeError: Object of type datetime is not JSON serializable

- **ID:** `python/flask-jsonify-datetime-serialization`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Returning datetime objects directly in JSON responses without custom serializer.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   from flask import Flask, jsonify
from datetime import datetime

app = Flask(__name__)

@app.route('/time')
def time():
    return jsonify({'time': datetime.now().isoformat()})
   ```
2. **** (90% success)
   ```
   Define custom JSONEncoder: class CustomJSONEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.isoformat()
        return super().default(obj)
app.json_encoder = CustomJSONEncoder
   ```

## Dead Ends

- **** — Duplicated code and easy to forget. (60% fail)
- **** — jsonify does not use json.dumps default; need custom encoder. (80% fail)
