(src: str)
| 170 | |
| 171 | # ---------------- JSON Lines ---------------- |
| 172 | def _parse_json_lines(src: str) -> Union[List[Any], None]: |
| 173 | lines = [ln.strip() for ln in src.splitlines() if ln.strip()] |
| 174 | if len(lines) <= 1: # 只有 0/1 行就不是 jsonl |
| 175 | return None |
| 176 | |
| 177 | objs: List[Any] = [] |
| 178 | for ln in lines: |
| 179 | try: |
| 180 | objs.append(json.loads(ln)) |
| 181 | except JSONDecodeError: |
| 182 | return None # 某行不是合法 JSON,放弃 jsonl 方案 |
| 183 | return objs |
| 184 | |
| 185 | |
| 186 | # ------------ 多对象提取(改进版) ------------ |