I am using json.loads to parse a JSON string. However, it identifies the string as invalid JSON when it contains escaped double quotes. Since the string itself is valid, how could I parse it correctly without modifying the input string (i.e. using \\" instead of \"). Here is my code:
import json
a = '{"name":"Nickname \"John\" Doe", "age":31, "Salary":25000}'
print ("initial strings given - \n", a)
try:
json_object1 = json.loads(a)
print ("Is valid json? true")
except ValueError as e:
print ("Is valid json? false")
Thanks!
'"\"'evaluates to the same string as'""'.jsongenerate the JSON from a dict would be simpler:a = json.dumps(dict(name='Nickname "John" Doe', age=31, Salary=25000)).