ToJSON: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Update Lua API reference
 
Complete Lua function catalog
Line 31: Line 31:
* JSON is limited to 16 KiB, 16 nested levels, and 2048 entries.
* JSON is limited to 16 KiB, 16 nested levels, and 2048 entries.


[[Category:Lua Functions]]
[[Category:Shared Functions]]
[[Category:Shared Functions]]
[[Category:Utility Functions]]
[[Category:Utility Functions]]

Revision as of 09:55, 15 August 2026

toJSON

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 16 KiB, 16 nested levels, and 2048 entries.