STRING::ESCAPE_JSON 1g 2024-05-07 laplante@plcb.ca GOWEB/STRING — Escape Strings for JSONtitle: “STRING::ESCAPE_JSON” version: “1g” date: 2024-05-07 section: “1g” author: “laplante@plcb.ca” category: “GOWEB/STRING”
string::escape_json(string)
escape_json(string)
string::escapeJson(string)
escapeJson(string)
The escape_json function escapes special characters in a string so it can be safely embedded inside a JSON string value.
Characters escaped include:
") → \"\) → \\\n, \r, \t, etc.\uXXXX (where XXXX is the Unicode code point in hexadecimal)&, <, >) are escaped to their Unicode representation (\u0026, \u003c, \u003e).This ensures that the resulting string is valid JSON and free from syntax-breaking characters.
res={{
escape_json("\"\n\tééèè");
escape_json('"&< >abc"');
}};
Returns:
res = "\"\n\tééèè"
"\"\u0026\u003c \u003eabc\""