Created
March 2, 2009 15:11
-
-
Save farcaller/72793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def FixFuckingJSON(s): | |
'''FixFuckingJSON(bad_json) -> good_json | |
Fixes integer keys in json | |
''' | |
RX=re.compile(r'(\d+)') | |
r = [] | |
m = RX.search(s) | |
while m: | |
r.append(m.group(1)) | |
s = s[:m.start()] + '\001\002' + s[m.end():] | |
m = RX.search(s) | |
i = 0 | |
p = s.find('\001\002') | |
while p != -1: | |
s = s[:p] + '"' + r[i] + '"' + s[p+2:] | |
p = s.find('\001\002') | |
i += 1 | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment