json.encode()
Encode a Lua value as JSON text.
Signature
json.encode(value): string
Parameters
| Parameter | Type | Description |
|---|---|---|
| value | any | String, number, boolean, nil, or a table |
Returns
string - JSON text.
Description
Tables with consecutive integer keys become JSON arrays; tables with string keys become
objects. Mixed or sparse tables throw an error. nil becomes null.
Example
local text = json.encode({ items = { "a", "b" }, ok = true })
-- {"items":["a","b"],"ok":true}