webmcp
view framework/env/encode/json.lua @ 568:c43f251262d8
More layout options for ui.paginate{...} and removed doc of non-implemented option
| author | jbe | 
|---|---|
| date | Wed Oct 13 16:48:34 2021 +0200 (2021-10-13) | 
| parents | 81d94b362043 | 
| children | 
 line source
     1 --[[--
     2 json_string =  -- JavaScript code
     3 encode.json(
     4   value        -- nil, false, true, a number, a string, or json.array{...} or json.object{...}
     5 )
     7 This function encodes any native datatype or table structure to JavaScript object notation (JSON). In order to distinguish between the empty array and the empty object, use json.array{} and json.object{} respectively.
     9 The return value of this function is additionally escaped in such way that it can be safely included in inline scripts both in HTML and XHTML (within CDATA section).
    11 --]]--
    13 function encode.json(obj)
    14   local str = json.export(obj)
    15   str = string.gsub(str, "</", "<\\/")
    16   str = string.gsub(str, "<!%[CDATA%[", "\\u003c![CDATA[")
    17   str = string.gsub(str, "]]>", "]]\\u003e")
    18   return str
    19 end
