Skip to main content

json.encode()

Encode a Lua value as JSON text.

Signature​

json.encode(value): string

Parameters​

ParameterTypeDescription
valueanyString, 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}