{
  "id": "go/encoding-json-marshal-infinite-recursion",
  "signature": "panic: json: infinite recursion (invalid cycle)",
  "signature_zh": "恐慌：json：无限递归（无效循环）",
  "regex": "panic:\\ json:\\ infinite\\ recursion\\ \\(invalid\\ cycle\\)",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A struct has a circular reference that causes json.Marshal to recurse infinitely, leading to a stack overflow.",
  "root_cause_type": "generic",
  "root_cause_zh": "结构体存在循环引用，导致json.Marshal无限递归，最终栈溢出。",
  "versions": [
    {
      "version": "1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding a depth counter to break recursion",
      "why_fails": "May still panic if depth exceeded; better to use custom marshaler.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Implement json.Marshaler to break cycles or use pointer indirection",
      "success_rate": 0.9,
      "how": "type Node struct {\n    Value int\n    Next  *Node\n}\nfunc (n *Node) MarshalJSON() ([]byte, error) {\n    if n == nil { return json.Marshal(nil) }\n    return json.Marshal(struct{ Value int }{Value: n.Value})\n}",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-07-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}