I have a textbox that posts info to the server and it's in JSON format. Lets say I want to enter two quotes for the value, and the JSON struct would look like:
{
"test": """"
}
I need it to look like:
{
"test": "\"\""
}
so it will follow JSON standards and can be parsable/stringifyable.
I tried using
var val = myVal.replace('"', "\\\"");
but this didn't work. val
ends up with only one escaped quote like so \""
Any help is much appreciated!
Use this
var val = myVal.replace(/"/g, '\\"');
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