File size: 392 Bytes
948e91c
60274d1
 
 
 
948e91c
 
 
60274d1
948e91c
60274d1
948e91c
60274d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import re
import json

def parse_json_garbage(s):
    s = s[next(idx for idx, c in enumerate(s) if c in "{["):]
    print(s)
    s = s[:next(idx for idx, c in enumerate(s) if c in "}]")+1]
    print(s)
    try:
        return json.loads(re.sub("[//#].*","",s,flags=re.MULTILINE))
    except json.JSONDecodeError as e:
        return json.loads(re.sub("[//#].*","",s,flags=re.MULTILINE))