I understand that there are many similar questions for json parsing when dealing with special escape characters, however i'm unable to find the solution. What i'm trying to do is save the following to a json file which i can later retrieve as a dict using json module from python. My json is something like this
{"head":{"body":{"/^\s+|\s+$":"", "\s+":" "}}}
When i tried to put it in json and loading it gives me a parsing error as is expected since backslash is not escaped. So i corrected it as follows (based on suggestions from SO):
{"head":{"body":{"/^\\s+|\\s+$":"", "\\s+":" "}}}
However when i load it to a dict, although it parses, it gives me the dict as follows:
{"head":{"body":{"/^\\s+|\\s+$":"", "\\s+":" "}}}
and not a single backslash as expected. How to deal with it, so that my \s has only single backslash and not two. Also i thought of going with ast.literal_eval() to read the data but don't want to go that way. Any suggestions on how to go about this.