MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / _extract_json_objects

Function _extract_json_objects

dataflow_agent/utils_common.py:187–209  ·  view source on GitHub ↗
(src: str)

Source from the content-addressed store, hash-verified

185
186# ------------ 多对象提取(改进版) ------------
187def _extract_json_objects(src: str) -> List[Any]:
188 dec = JSONDecoder()
189 idx, n = 0, len(src)
190 objs: List[Any] = []
191
192 while idx < n:
193 m = re.search(r'[{\[]', src[idx:])
194 if not m:
195 break
196 idx += m.start()
197 try:
198 obj, end = dec.raw_decode(src, idx)
199 # ========== 严格性检查 ==========
200 tail = src[end:].lstrip()
201 # 允许结束、逗号、换行、右括号、右中括号
202 if tail and tail[0] not in ',]}>\n\r':
203 idx += 1 # 可能是误判,如 {"a":1 <-- 缺 }
204 continue
205 objs.append(obj)
206 idx = end
207 except JSONDecodeError:
208 idx += 1
209 return objs
210
211
212def _maybe_merge(objs: List[Any], merge_dicts: bool) -> Union[Any, List[Any]]:

Callers 1

robust_parse_jsonFunction · 0.85

Calls 2

searchMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected