Data
Encoding and decoding values.
json.encode
Section titled “json.encode”json.encode(value) --> stringTurn a Lua value into a JSON string. Server and client.
| Parameter | Type | Description |
|---|---|---|
value |
any |
Table, string, number, boolean or nil. |
Returns
string: JSON text.
local text = json.encode({ name = 'Max', cash = 100 })Compared to FiveM: Same as in FiveM.
json.decode
Section titled “json.decode”json.decode(text) --> any, string?Turn a JSON string into a Lua value. Server and client.
| Parameter | Type | Description |
|---|---|---|
text |
string |
JSON text. |
Returns
any: The value, or nil if the text is not valid JSON.string?: Error message when decoding failed.
local data, err = json.decode('{"cash": 100}')if not data then print(err) endCompared to FiveM: FiveM throws on invalid JSON; GAMPEON returns nil and an error message.