ToJSON: Difference between revisions
Jump to navigation
Jump to search
Complete Lua function catalog |
Document expanded scripting capacities and complete audited limits for 0.1.3 BUILD81 |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
= toJSON = | = toJSON = | ||
<div style="background:#fff5f5; border:1px solid #d13b3b; border-left:5px solid #d13b3b; color:#111111; padding:0.85rem 1rem; margin:0.75rem 0 1rem;"> | |||
<div style="color:#111111; font-weight:bold; letter-spacing:0.04em;">IMPROVED FROM UPDATE 0.1.2</div> | |||
<div style="color:#111111; margin-top:0.25rem;">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.</div> | |||
</div> | |||
Serializes a supported Lua value to bounded JSON. | Serializes a supported Lua value to bounded JSON. | ||
| Line 29: | Line 33: | ||
== Notes == | == Notes == | ||
* Available in both server-side and client-side resource scripts. | * Available in both server-side and client-side resource scripts. | ||
* JSON is limited to | * JSON is limited to 1 MiB, 64 nested levels, and 65536 cumulative entries. | ||
* Expanded limits apply from update 0.1.3 BUILD81. See [[Scripting limits]]; earlier 0.1.3 binaries retain their old limits. | |||
[[Category:Lua Functions]] | [[Category:Lua Functions]] | ||
[[Category:Shared Functions]] | [[Category:Shared Functions]] | ||
[[Category:Utility Functions]] | [[Category:Utility Functions]] | ||
Latest revision as of 11:51, 12 September 2026
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 1 MiB, 64 nested levels, and 65536 cumulative entries.
- Expanded limits apply from update 0.1.3 BUILD81. See Scripting limits; earlier 0.1.3 binaries retain their old limits.