Ok I assume that you have a line in the form {"key": "value"} , in which the value can contain quotes without quotes. In your example, we have Grade for the key and "B+" for the value.
In this case, you can either remove the inner quotation marks or quote them correctly, but you must split the string to determine the value
start, value, last = re.match(r'(\s*{\s*".*?"\s*:\s*")(.*)("\s*})', doc).groups()
Then you can easily handle quotation marks in terms of values:
fixed = value.replace('"', "") # remove quotes
or
fixed = value.replace('"', r'\"')
Then you can successfully write:
d = ast.litteral_eval(start + fixed + last)
and get either {'Grade': ' B+ '} or {'Grade': ' "B+" '}
source share