Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created March 2, 2009 15:11
Show Gist options
  • Save farcaller/72793 to your computer and use it in GitHub Desktop.
Save farcaller/72793 to your computer and use it in GitHub Desktop.
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