This is going to sound really ghetto, but I need to print some Javascript to the browser screen so that it can be cut and pasted into another program.
I'm using JSON.stringify()
from json2.js
, however, its not escaping characters such as quotes and new lines (",\n) which are actually control parts of a JSON object and need to be escaped.
For example, I'd get strings like this that cause problems when importing into the other program:
{
string_property_01 : "He said "HI""; // The string terminates after "He said "
}
Are there any libraries that I can use to escape all the characters that I need to escape here?
Thanks!
I do the following, its a beautiful hack.
var g = {
sampleFunc : function (data) {
var dataAsText = JSON.stringify(data);
var response = prompt('you can copy and paste this', dataAsText);
}
}
// usage...
g.sampleFunc({ id: "4", name: "John Smith" });
JavaScript prompt... gotta love it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With