{
  "id": "python/django-json-response-serialization",
  "signature": "TypeError: Object of type 'MyModel' is not JSON serializable",
  "signature_zh": "TypeError: 类型为'MyModel'的对象不是JSON可序列化的",
  "regex": "TypeError:\\ Object\\ of\\ type\\ 'MyModel'\\ is\\ not\\ JSON\\ serializable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Trying to return a Django model instance directly in JsonResponse without serializing to dict.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试在JsonResponse中直接返回Django模型实例，而未序列化为字典。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Produces a string representation, not useful JSON data.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Still fails because model instance is not JSON serializable.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use model_to_dict: from django.forms.models import model_to_dict; return JsonResponse(model_to_dict(instance))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Create a custom serializer: return JsonResponse({'id': instance.id, 'name': instance.name})",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-19",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}