I'm doing something very similar to what this user was doing: trying to load a javascript object declaration into a python dictionary. However, unlike that user, the property names aren't enclosed in quotes.
>>> simplejson.loads('{num1: 1383241561141, num2: 1000}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lalalal/site-packages/simplejson/__init__.py", line 385, in loads
return _default_decoder.decode(s)
File "/Users/lalalal/site-packages/simplejson/decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/lalalal/site-packages/simplejson/decoder.py", line 418, in raw_decode
obj, end = self.scan_once(s, idx)
simplejson.decoder.JSONDecodeError: Expecting property name: line 1 column 1 (char 1)
It'd be just splendid if I had the correct JSON notation:
>>> simplejson.loads('{"num1": 1383241561141, "num2": 1000}')
{'num1': 1383241561141, 'num2': 1000}
But, I don't. How can I work around this? Maybe it comes down to something as simple as a regex?
Edit: This regex that Martijn wrote has me halfway there, it just doesn't work if I have trailing whitespace after the braces which happens in some of my example data, e.g. { num1: 1383241561141, num2: 1000}'
re.sub?