t1 =
"""
{"abc": "{\"version\": \"1\"}"}
"""
ans = json.loads(t1)
Above code results in error as Python doesn’t like that I’m providing dictionary as a string value of key "abc".
Assuming I cannot change the input mentioned above, I want to be able to decode the above-mentioned string in Python as JSON, how can I solve this problem?
>Solution :
That’s not a valid json string. You need to lose the extra quotes. Only the entire thing needs to be a string, not each individual value.
In [1]: t1 = '{"abc": {"version": "1"}}'
In [2]: import json
In [3]: ans = json.loads(t1)
In [4]: ans
Out[4]: {'abc': {'version': '1'}}