Here's roughly how to escape the string:
String.prototype.toJSON = function() { return '\''+ this.replace(/[\\"'\x00-\x1F\u0080-\uFFFF]/g, function(c) { switch (c) { case "\b": return '\\b'; case "\t": return '\\t'; case "\n": return '\\n'; case "\f": return '\\f'; case "\r": return '\\r'; case '"' : return '\\"'; case '\'': return '\\\''; case '\\': return '\\\\'; } return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4); }) +'\''; }
Here's roughly how to escape the string:
String. prototype. toJSON = function() /[\\"'\ x00-\x1F\ u0080-\ uFFFF]/ g, function(c) { 0).toString( 16)).slice( -4);
{
return '\''+ this.replace(
switch (c) {
case "\b": return '\\b';
case "\t": return '\\t';
case "\n": return '\\n';
case "\f": return '\\f';
case "\r": return '\\r';
case '"' : return '\\"';
case '\'': return '\\\'';
case '\\': return '\\\\';
}
return '\\u' + ('0000' + c.charCodeAt(
}) +'\'';
}