Function
toJSON
Turns a Lua value (a number, a string, a table, an element) into JSON text, e.g. to store in a file, a database or account data. The format is the same: the result is always a JSON array, and elements are written so that fromJSON can read them back. A table that appears a second time (including a table that contains itself) is written as a "^T^n" reference, and fromJSON restores it as the same table.
Syntax
string toJSON(mixed value [, bool compact = false, string prettyType = "none"])Arguments
valuemixed- The value to store.
compactbool, optional = falsetrue= no spaces.prettyTypestring, optional = "none""none","spaces"or"tabs"(indentation).
Returns
JSON text or false.
Example
local data = { money = 500, cars = { 411, 560 } }
local text = toJSON(data, true)
outputServerLog(text) -- [{"cars":[411,560],"money":500}]