FromJSON: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Complete Lua function catalog
Document Lua APIs available or improved from G1R:MP 0.1.2
Line 1: Line 1:
<!-- This page is generated automatically from the function definition: fromJSON. -->
= fromJSON =
= fromJSON =
<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>
Parses bounded JSON into Lua values.
Parses bounded JSON into Lua values.


Line 12: Line 16:
! Name !! Type !! Required !! Description
! Name !! Type !! Required !! Description
|-
|-
| <code>json</code> || <code>string</code> || yes || A UTF-8 JSON document up to 16 KiB.
| <code>json</code> || <code>string</code> || yes || A UTF-8 JSON document up to 32 KiB.
|}
|}


Line 31: Line 35:
== 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 16 KiB, 16 nested levels, and 2048 entries.
* JSON is limited to 32 KiB, 16 nested levels, and 2048 entries.


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

Revision as of 18:40, 3 September 2026

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 32 KiB.

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