When I call JSON.stringify() on a complex object in JavaScript, it produces a string with lots of escape sequences (\\\", \\\\\", etc.).
How can I make it create a h
You can use the replacer. The second parameter provided by JSON.stringify.Replacer could be a function or array.
In your case we can create a function which replaces all the special characters with a blank space.The below example replaces the whitespaces and underscores.
function replacer(key, value) {
return value.replace(/[^\w\s]/gi, '');
}
var foo = {"a":"1","b":2};
var jsonString = JSON.stringify(foo, replacer);
If you simply want to replace the one special character, use:
JSON.stringify({ a: 1, b: 2 }, null, '\t');
For more information on replacer, check the MDN page JSON.stringify().