MCPcopy Index your code
hub / github.com/going-doer/Paper2Code / content_to_json2

Function content_to_json2

codes/utils.py:45–68  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

43
44
45def content_to_json2(data):
46 # remove [CONTENT][/CONTENT]
47 clean_data = re.sub(r'\[CONTENT\]|\[/CONTENT\]', '', data).strip()
48
49 # "~~~~", #comment -> "~~~~",
50 clean_data = re.sub(r'(".*?"),\s*#.*', r'\1,', clean_data)
51
52 # "~~~~" #comment → "~~~~"
53 clean_data = re.sub(r'(".*?")\s*#.*', r'\1', clean_data)
54
55
56 # ("~~~~",] -> "~~~~"])
57 clean_data = re.sub(r',\s*\]', ']', clean_data)
58
59 clean_data = re.sub(r'\n\s*', '', clean_data)
60
61 # JSON parsing
62 try:
63 json_data = json.loads(clean_data)
64 return json_data
65
66 except json.JSONDecodeError as e:
67 # print("Json parsing error", e)
68 return content_to_json3(data)
69
70def content_to_json3(data):
71 # remove [CONTENT] [/CONTENT]

Callers 1

content_to_jsonFunction · 0.85

Calls 1

content_to_json3Function · 0.85

Tested by

no test coverage detected