It looks like you're new here. If you want to get involved, click one of these buttons!
Likes: MoKaLux
Comments
for reference: https://www.freeformatter.com/json-escape.html
function escape_json_string(text)
local replacements = {
["\\"] = "\\\\",
["\""] = "\\\"",
["\b"] = "\\b",
["\f"] = "\\f",
["\n"] = "\\n",
["\r"] = "\\r",
["\t"] = "\\t"
}
return text:gsub("[\"\\%c]", replacements)
end
function unescape_json_string(text)
local replacements = {
['\\"'] = '"',
["\\\\"] = "\\",
["\\b"] = "\b",
["\\f"] = "\f",
["\\n"] = "\n",
["\\r"] = "\r",
["\\t"] = "\t"
}
return text:gsub("\\[\"\\bfnrt]", replacements)
end
Likes: MoKaLux