I’m kind of new to python. 25 years of coding with different languages (Pascal/Pascal Object, C, PHP, javascript/typescript)
I’m using python 3.8, and requests
to make API calls
I’m receiving from an API JSON datas with double backslash.
"address_1": "\",
They seems to be lost when using the .json()
method of requests.Response
.
So when I save those datas into an mariaDb database, and try to use JSON function, maria complains of unvalid JSON
Why ??
First I try to test json.loads()
Guess a user type hello into an input on a webpage
I want to transform this valid JSON object into a dict
{"input": "hel\lo"}
why do I get an exception with this code ?
string = '{"input": "hel\lo"}'
dict = json.loads(string)
print(dict)
Invalid escape: line 1 column 15 (char 14)
File "/home/michel/sources/test.py", line 5, in <module>
dict = json.loads(string)
json.decoder.JSONDecodeError: Invalid escape: line 1 column 15 (char 14)
but not with this one ?
string = '{"input": "hel\lo"}'
dict = json.loads(string)
print(dict)
Insane
string = json.dumps(dict)
string value with vscode is '{"input": "hel\\lo"}'
1