Is there a function to escape special charcters like " and ' and \ etc. for text to put into JSON fields?
The text is for HTML.
Is there a function to escape special charcters like " and ' and \ etc. for text to put into JSON fields?
The text is for HTML.
Howdy. I'm curious. What kind of actual data are you using?
I put together this function:
Let ([
_j = "Jeremy\\s";
_end = ""
];
JSONSetElement ( "" ; "name" ; _j ; JSONString )
)
And found nothing wrong. It produces {"name": "Jeremy\\s"}
I think as long as you use JSONString as the 4th parameter, it should handle the characters just fine.
MBS( "JSON.CreateString"; "Jeremy's test\test" )
returns "Jeremy's test\\test" for our plugin.
MBS( "Text.EncodeToHTML"; "Test äöü & \ \" " )
gives "Test äöü & \ " "
Double quotes in JSON will be escaped if you use the JSONSetElement function. Or if you need them to be html encoded, you can substitute them with " as has been mentioned, but if you want to retain smart quotes, you will want to sub those out as well and replace with correct html entities.
If you use the JSONSetElement function, does that work for you?
So far I got this:
Substitute ( $text;
[Char(9); "	"];
[Char(13); "
"];
["\\"; "\"];
["\""; """]
)
But I am not sure is tehre is anything else.