Skip to content

json_decode

json_decode(string) parses a JSON string into a native Lua table. Returns (value, nil) on success, or (nil, error_message) on failure.

json_decode(string)
sync
Param Type Description
string string The JSON string to parse
Value Type Description
1st any / nil Parsed Lua value, or nil on malformed JSON
2nd string / nil Error message, or nil on success
local data, err = json_decode('{"status": "ok", "count": 42}')
if not data then
log("decode failed: " .. err)
return
end
log("Status is: " .. data.status)