MCPcopy Create free account
hub / github.com/DVampire/FinAgent / refine_json

Function refine_json

finagent/utils/json_utils.py:32–48  ·  view source on GitHub ↗
(json_string)

Source from the content-addressed store, hash-verified

30 return False
31
32def refine_json(json_string):
33 json_string = json_string.strip().replace('\r', '').replace('\t', '').replace('\n', '').replace('\\', '')
34
35 json_string = re.sub(r',\s*([}\]])', r'\1', json_string)
36 json_string = re.sub(r'\.\s*([}\]])', r'\1', json_string)
37
38 pattern = r"\{(.*)\}"
39 match = re.search(pattern, json_string, re.DOTALL)
40
41 if match:
42 json_string = "{" + match.group(1) + "}"
43 if check_json(json_string):
44 return json_string
45 else:
46 return json_string
47
48 return json_string
49
50
51def parse_semi_formatted_json(json_string):

Callers 1

Calls 1

check_jsonFunction · 0.85

Tested by

no test coverage detected