Improves jsonencode function

This commit is contained in:
Simone Mainardi 2016-08-09 18:17:39 +02:00
parent 52abb7659a
commit 0b1f12f928
3 changed files with 12 additions and 3 deletions

View file

@ -2147,9 +2147,17 @@ end
-- TODO: improve this function
function jsonencode(what)
tprint(what)
what = string.gsub(what, '"', "'")
-- everything but all ASCII characters from the space to the tilde
what = string.gsub(what, "[^ -~]", " ")
-- cleanup line feeds and carriage returns
what = string.gsub(what, "\n", " ")
what = string.gsub(what, "\r", " ")
-- escape all the remaining backslashes
what = string.gsub(what, "\\", "\\\\")
-- max 1 sequential whitespace
what = string.gsub(what, " +"," ")
return(what)
end