I can't escape a new line when it is in an object. I just did this in Node. Anyone have an idea how this can be done?
var result = {
key1: "This is a line\n with new\n lines\n.",
key2: "No new lines here."
};
Here are my results:
result
Object
var myTemp = JSON.stringify(result);
Here are the results
myTemp
{"key1":"This is a line\n with new\n lines\n.","key2":"No new lines here."}
var newTemp = myTemp.replace(/\\n/g, "\\n");
Finally, here are the final results.
newTemp
{"key1":"This is a line\n with new\n lines\n.","key2":"No new lines here."}
Notice how it is still \n
, not \\n
.