import sys f = open("/data/ai/audio/server/temp/rich-outline-fail_43_1782982196341.txt") s = f.read() # extract pure JSON import re m = re.search(r'(\{"mainTheme".*\})\s*$', s, re.DOTALL) if not m: print("no json found") sys.exit(0) json_str = m.group(1) print("json len=", len(json_str)) print("---around keyPoints---") idx = json_str.find('"keyPoints":[') print(json_str[idx:idx+800]) print("---try parse---") import json try: j = json.loads(json_str) print("OK, chapters=", len(j.get('chapters', []))) except Exception as e: print("parse error:", e) print("---try jsonrepair---") try: from json_repair import repair_json out = repair_json(json_str, return_objects=True) print("repaired type:", type(out)) if isinstance(out, dict): print("repaired chapters=", len(out.get('chapters', []))) else: print("repaired first 200:", str(out)[:200]) except Exception as e2: print("jsonrepair error:", e2)