{
  "id": "go/json-marshal-error-unsupported-type",
  "signature": "json: unsupported type: map[int]string",
  "signature_zh": "json: 不支持的类型：map[int]string",
  "regex": "json: unsupported type: map\\[.*\\]",
  "domain": "go",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "Attempting to marshal a Go type with keys that are not strings, which JSON format does not support (JSON object keys must be strings).",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试编组键不是字符串的 Go 类型，JSON 格式不支持（JSON 对象键必须是字符串）。",
  "versions": [
    {
      "version": "go1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "MarshalIndent also calls json.Marshal internally; same error occurs.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Returning nil causes json.Marshal to serialize the value as 'null', not skip it; error still may occur depending on implementation.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Convert map keys to strings before marshaling: `newMap := make(map[string]string); for k, v := range oldMap { newMap[fmt.Sprintf(\"%d\", k)] = v }`",
      "success_rate": 0.95,
      "how": "Convert map keys to strings before marshaling: `newMap := make(map[string]string); for k, v := range oldMap { newMap[fmt.Sprintf(\"%d\", k)] = v }`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Define a custom struct or use a slice of key-value pairs instead: `type Entry struct { Key int; Value string }` then marshal `[]Entry`.",
      "success_rate": 0.9,
      "how": "Define a custom struct or use a slice of key-value pairs instead: `type Entry struct { Key int; Value string }` then marshal `[]Entry`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Convert map keys to strings before marshaling: `newMap := make(map[string]string); for k, v := range oldMap { newMap[fmt.Sprintf(\"%d\", k)] = v }`",
    "Define a custom struct or use a slice of key-value pairs instead: `type Entry struct { Key int; Value string }` then marshal `[]Entry`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/encoding/json#Marshal",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}