I have the string with backslashes:
const str = 'E:\\music\\post'; // It represents "E:\music\post" text in HTML
JSON.stringify(str)
returns "the same" string '"E:\\music\\post"'
. Why not '"E:\\\\music\\\\post"'
?
JSON.parse('"E:\\music\\post"')
will throws the error: Uncaught SyntaxError: Unexpected token m in JSON at position 4
.
JSON.parse('"E:\\\\music\\\\post"')
works OK.
But another strange thing is that JSON.parse(JSON.stringify("E:\\music\\post"))
works well. Why?
That is the better workaround for it? I want to save the string to json file, and later to create an object from the json file.