(data)
| 43 | |
| 44 | |
| 45 | def 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 | |
| 70 | def content_to_json3(data): |
| 71 | # remove [CONTENT] [/CONTENT] |
no test coverage detected