ToJSON
toJSON
IMPROVED FROM UPDATE 0.1.2
This function is available in earlier releases and has corrected or expanded behavior in G1R:MP 0.1.2 and later. The contract below describes the updated behavior.
Serializes a supported Lua value to bounded JSON.
Syntax
string|false json, string|nil error = toJSON(mixed value)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
mixed |
yes | A nil, boolean, finite number, string, or acyclic table containing supported values. |
Returns
Returns the JSON string and nil on success. On failure it returns false and an error string.
Examples
Encode a compact payload:
local json, errorMessage = toJSON({ playerId = playerId, ready = true })
if not json then
outputDebugString(errorMessage)
end
Notes
- Available in both server-side and client-side resource scripts.
- JSON is limited to 32 KiB, 16 nested levels, and 2048 entries.