jbe/bsw@0: --[[-- jbe@285: json_string = -- JavaScript code jbe/bsw@0: encode.json( jbe@285: value -- nil, false, true, a number, a string, or json.array{...} or json.object{...} jbe/bsw@0: ) jbe/bsw@0: jbe@285: 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. jbe@10: jbe@285: 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). jbe@223: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function encode.json(obj) jbe@293: local str = json.export(obj) jbe@285: str = string.gsub(str, "", "]]\\u003e") jbe@285: return str jbe/bsw@0: end