# JSON解析器静默将BOM字符读入第一个键名

- **ID:** `data/json-utf8-bom-silent-read`
- **领域:** data
- **类别:** encoding_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Windows编辑器保存的UTF-8 BOM文件（字节顺序标记\ufeff）导致未去除BOM的JSON解析器将其包含在第一个键名中，造成键查找失败和静默数据损坏。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Python 3.11 | active | — | — |
| Python 3.12 | active | — | — |
| Node.js 20 | active | — | — |
| jq 1.7 | active | — | — |

## 解决方案

1. ```
   Open file with utf-8-sig encoding before parsing: `with open('data.json', encoding='utf-8-sig') as f: data = json.load(f)`
   ```
2. ```
   Strip BOM from file content before parsing: `content = open('data.json', 'rb').read().lstrip(b'\xef\xbb\xbf'); data = json.loads(content)`
   ```

## 无效尝试

- **** — Python's json.load does not accept encoding parameter; you must use open() with encoding='utf-8-sig' before json.load. (50% 失败率)
- **** — This modifies the source file and may be forgotten in CI/CD pipelines; also requires root access in some environments. (40% 失败率)
- **** — This breaks all key lookups in downstream code and makes the code non-portable across different editors. (90% 失败率)
