string json.encode(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 = json.encode({ x = 1.5, tags = { "a", "b" } }, true)
print(text)NoteElements, functions, NaN, infinity, keys that are neither strings nor numbers and tables nested over 32 levels raise a Lua error.