Handling lazy JSON in Python – ‘Expecting property name’

You’re trying to use a JSON parser to parse something that isn’t JSON. Your best bet is to get the creator of the feeds to fix them.

I understand that isn’t always possible. You might be able to fix the data using regexes, depending on how broken it is:

j = re.sub(r"{\s*(\w)", r'{"\1', j)
j = re.sub(r",\s*(\w)", r',"\1', j)
j = re.sub(r"(\w):", r'\1":', j)

Leave a Comment