When sending data to front-end from back-end, how can I pass JSON string with quotes, so how can I escape quotes in json? So I can pass JSON as below
"WeekDays": {
"Sunday": {
"text1": "Good morning",
"text2": "Some more \"Example text\" here "
}
}
Thanks
If you want to escape double quotes in JSON, you can simply use below JSON
'{"Text":"Hello \\"My Name\\" is Vikas"}'
Which will be converted into
'{"Text":"Hello "My Name" is Vikas"}'
Above example also works with JSON.Parse in Javascript.
var jsontext = '{"Text":"Hello \\"My Name\\" is Vikas"}'
console.log(JSON.parse(jsontext));
//output
//{
// Text: "Hello \"My Name\" is Vikas"
//}
OR
Use Raw strings
console.log(JSON.parse(String.raw`"Some example of double quote >> \" <<"`));
That's it, any of the above should work.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly