{
  "id": "data/json-utf8-bom-silent-read",
  "signature": "JSON parser silently reads BOM character as part of first key name",
  "signature_zh": "JSON解析器静默将BOM字符读入第一个键名",
  "regex": "(?:BOM|\\\\ufeff|KeyError.*\\ufeff|first key.*bom)",
  "domain": "data",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "Files saved with UTF-8 BOM (Byte Order Mark, \\ufeff) by Windows editors cause JSON parsers that do not strip BOM to include it in the first key name, leading to key lookup failures and silent data corruption.",
  "root_cause_type": "generic",
  "root_cause_zh": "Windows编辑器保存的UTF-8 BOM文件（字节顺序标记\\ufeff）导致未去除BOM的JSON解析器将其包含在第一个键名中，造成键查找失败和静默数据损坏。",
  "versions": [
    {
      "version": "Python 3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Python 3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Node.js 20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "jq 1.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Python's json.load does not accept encoding parameter; you must use open() with encoding='utf-8-sig' before json.load.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This modifies the source file and may be forgotten in CI/CD pipelines; also requires root access in some environments.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This breaks all key lookups in downstream code and makes the code non-portable across different editors.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Open file with utf-8-sig encoding before parsing: `with open('data.json', encoding='utf-8-sig') as f: data = json.load(f)`",
      "success_rate": 0.95,
      "how": "Open file with utf-8-sig encoding before parsing: `with open('data.json', encoding='utf-8-sig') as f: data = json.load(f)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Strip BOM from file content before parsing: `content = open('data.json', 'rb').read().lstrip(b'\\xef\\xbb\\xbf'); data = json.loads(content)`",
      "success_rate": 0.93,
      "how": "Strip BOM from file content before parsing: `content = open('data.json', 'rb').read().lstrip(b'\\xef\\xbb\\xbf'); data = json.loads(content)`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Open file with utf-8-sig encoding before parsing: `with open('data.json', encoding='utf-8-sig') as f: data = json.load(f)`",
    "Strip BOM from file content before parsing: `content = open('data.json', 'rb').read().lstrip(b'\\xef\\xbb\\xbf'); data = json.loads(content)`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.python.org/3/library/json.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-09-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}