How it works
create object with json string as value
>>> o = {"foo": "foo"}
>>> oo = {"bar": json.dumps(o)}
>>> oo
{'bar': '{"foo": "foo"}'}
>>> json.dumps(oo)
'{"bar": "{\\"foo\\": \\"foo\\"}"}'
>>> s = json.dumps(oo)[9:-2]
>>> s
'{\\"foo\\": \\"foo\\"}'
reproduce error
>>> r = json.loads(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
solve error by nesting json
>>> r = json.loads('{"foo": "' + s + '"}')
>>> r
{'foo': '{"foo": "foo"}'}
>>> json.loads(r["foo"])
{'foo': 'foo'}