{
  "id": "python/flask-jsonify-serialization-error",
  "signature": "TypeError: Object of type datetime is not JSON serializable",
  "signature_zh": "类型错误：datetime类型的对象无法JSON序列化",
  "regex": "TypeError:\\ Object\\ of\\ type\\ datetime\\ is\\ not\\ JSON\\ serializable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Returning a datetime or other non-serializable object directly from a Flask route without converting it to a string or using a custom encoder.",
  "root_cause_type": "generic",
  "root_cause_zh": "在Flask路由中直接返回datetime或其他不可序列化的对象，而没有转换为字符串或使用自定义编码器。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Using str(datetime) converts to a string but loses formatting and may cause inconsistent output.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Setting app.json_encoder = None does not fix the issue and may break other serialization.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Define a custom JSON encoder: class CustomEncoder(json.JSONEncoder):\\n    def default(self, obj):\\n        if isinstance(obj, datetime):\\n            return obj.isoformat()\\n        return super().default(obj)\\napp.json_encoder = CustomEncoder",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Convert datetime to ISO format manually: return jsonify({'time': datetime.now().isoformat()})",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}