FromJSON

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search

fromJSON

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.

Parses bounded JSON into Lua values.

Syntax

mixed|false value, string|nil error = fromJSON(string json)

Parameters

Name Type Required Description
json string yes A UTF-8 JSON document up to 1 MiB.

Returns

Returns the decoded value and nil on success. On failure it returns false and an error string.

Examples

Decode a JSON payload safely:

local value, errorMessage = fromJSON(payload)
if value == false then
    outputDebugString(errorMessage)
else
    outputDebugString(tostring(value.ready))
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.