my_json = '{"hello":"\\x20\\x20\\x20\\x3Cdiv\\x3E\\x20\\x0A\\x20\\x20\\x20\\x20\\HELLO"}'
json.loads(my_json)
I get this.
JSONDecodeError: Invalid \escape: line 1 column 11 (char 10)
What conversion do i need to use so my json will load?
my_json = '{"hello":"\\x20\\x20\\x20\\x3Cdiv\\x3E\\x20\\x0A\\x20\\x20\\x20\\x20\\HELLO"}'
json.loads(my_json)
I get this.
JSONDecodeError: Invalid \escape: line 1 column 11 (char 10)
What conversion do i need to use so my json will load?
just first convert python string into json and it will work for you.
my_json = json.dumps({
"hello":"\\x20\\x20\\x20\\x3Cdiv\\x3E\\x20\\x0A\\x20\\x20\\x20\\x20\\HELLO"
})
json.loads(my_json)
The suggestion of @pguardiario definitely is cleaner, but if you're just after the resulting dict
, give eval a try:
In [77]: my_json
Out[77]: '{"hello":"\\x20\\x20\\x20\\x3Cdiv\\x3E\\x20\\x0A\\x20\\x20\\x20\\x20\\HELLO"}'
In [78]: evaluated = eval(my_json)
Out[78]: {'hello': ' <div> \n \\HELLO'}
In [79]: evaluated.items()
Out[79]: dict_items([('hello', ' <div> \n \\HELLO')])