M MY Multiplayer: Wiki
Side
Kind

fromJSON

Shared

Turns JSON text into a Lua value. It is the same function as json.decode.

any fromJSON(string json)

Parameters

NameTypeDescription
jsonstringThe JSON text.

Returns

The value read. If the text is not valid JSON, nil and a message saying what is wrong and where.

Objects and arrays become tables, and null becomes nil (in an array, it leaves a hole). Whole numbers become Lua integers. Over 32 levels of nesting are refused.

Example

local data, problem = fromJSON('{"name":"Carl","money":350}')
if problem then
    outputDebugString("Bad JSON: " .. problem, 2)
else
    print(data.name, data.money)
end

See also