wolfhacklua API 1.1 Forum

json

Turn Lua tables into JSON text and back.

since 1.0no permission needed

Reference#

json.encode#since 1.0

json.encode(value: any, pretty?: boolean): string

Serialises a value.

ParameterTypeDescription
valueanyA table, string, number or boolean. Functions and cycles are errors.
pretty optionalbooleanIndent the output. default false
ReturnsDescription
stringThe JSON text.
lua
local text = json.encode({ name = "x", list = { 1, 2, 3 } }, true)

json.decode#since 1.0

json.decode(text: string): any | nil, string?

Parses JSON.

ParameterTypeDescription
textstringJSON text.
ReturnsDescription
any | nilThe value, or nil when the text is not valid JSON.
string?The error message when it is nil.
lua
local data, err = json.decode(response.body)
if not data then log.warn(err) end
API 1.1 · source docs-src/api/json.json