I am creating a json body for a REST payload body like so:
>>> j = json.loads('["foo", {"bar": ["to_be_replaced", 1.1, 1.0, 2]}]')
>>> text = "aaaa" + "\\" + "bbbbb" + "\\" + "cccc"
>>> j[1]["bar"][0] = text
>>> j
['foo', {'bar': ['aaaa\\bbbbb\\cccc', 1.1, 1.0, 2]}]
Annoyingly, the format expected on the other side is like so
"aaaa\bbbb\cccc".
A terrible idea, I know.
I have tried everything and am starting to believe it's simply impossible to store text in this format in a json object. Is there a way? Or do I need to get the developers of the webservice to choose a more sensible delimiter.
I know it's REALLY a single backslash and if I do a print a get a single backslash
>>> print(text)
aaaa\bbbbb\cccc
But that doesn't help me get it into a json object.