the value includes back slash and slash, I'd like to keep the format
NOTES: I don't want to change the original json file as some answers to ask to escape the slash first. You never know which value should be escape, which should not. The sample is simple, but the real json file is bigger. I just need same data to be read and output as exact same.
$ cat a.json
{
"name": "url",
"value": "https:\/\/www.example.com"
}
but when export its value, the back slash is gone.
$ cat a.js
var fs = require("fs");
var content = fs.readFileSync("a.json");
var json = JSON.parse(content);
console.log(json)
fs.writeFile("output", json.value, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
Here is the test result
$ node a.js
{ name: 'url', value: 'https://www.example.com' }
The file was saved!
$ cat output
https://www.example.com
Which I still want to save the original value to the file
https:\/\/www.example.com
How to do that?