string toJSON(any value [, bool pretty = false])
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The value: nil, a boolean, a number, a string, a vector or a table. |
| pretty | bool | If true, the text is indented over several lines.default false |
Returns
The JSON text.
A table with keys 1 to n and no holes (or an empty one) becomes an array; any other becomes an object, its number keys written as strings. A vector becomes an array of numbers.
Example
local text = toJSON({ name = "Carl", money = 350, weapons = { 22, 31 } })
-- {"name":"Carl","money":350,"weapons":[22,31]}NoteElements, functions, NaN, infinity, keys that are neither strings nor numbers and tables nested over 32 levels raise a Lua error.