What would be the fastest way (execution wise) to to json.loads on this sort of input string:
istr=""" {u'topic': u'dl_job', u'url': u'http://somedomain.com' }"""
I don’t have much control over what is passed as istr.
NOTES:
- json.loads doesn’t like the leading
u - nor does it like strings being delimited by
'instead of"
Updated: I know I could play dirty tricks like replacing the u and ' but I was wondering if there is a cleaner solution.
If this is a Python data structure (as it looks like), the function you want is
ast.literal_eval.http://docs.python.org/library/ast#ast.literal_eval
This is similar to just calling
eval, but literal_eval is safe, because it won’t call any functions or anything, just parse literals (i.e. lists, dicts, strings, numbers, etc.).