I am extracting a postgres table as json. The output file contains lines like:
{\"data\": {\"test\": 1, \"hello\": \"I have \\\" !\"}, \"id\": 4}
You can specify so called “raw strings”:
>>> print r'{"data": {"test": 1, "hello": "I have \" !"}, "id": 4}'
{"data": {"test": 1, "hello": "I have \" !"}, "id": 4}
They don’t interpret the backslashes.
Usual strings change \" to ", so you can have " characters in strings that are themselves limited by double quotes:
>>> "foo\"bar"
'foo"bar'
So the transformation from \" to " is not done by json.loads, but by Python itself.