json
The json namespace provides high-speed JSON encoding and decoding.
Type Mapping & Rules
Section titled βType Mapping & Rulesβ- Numbers: Preserves integer vs float representations (e.g.
64stays64, not64.0). - Arrays: 1-based sequential Lua tables (
1..n) serialize into JSON arrays[...]and parse back into sequential tables. - Objects: Key-value tables serialize into JSON objects
{...}. - Userdata: Types like
vector,qangle, andcolorserialize asnull. Extract primitive coordinates/channels before stringifying. - Recursion Safety: Nested tables automatically halt at 32 recursion levels to prevent stack overflow.
Functions
Section titled βFunctionsβ| Function | Parameters | Returns | Description |
|---|---|---|---|
json.parse |
text: string |
table |
Parses a JSON string into a Lua table. |
json.stringify |
tbl: table, indent?: number |
string |
Serializes a Lua table into a JSON string with optional space indentation. |
json.pretty |
tbl: table, indent?: number |
string |
Pretty-prints JSON (default indentation: 4 spaces). |
Example
Section titled βExampleβlocal payload = { tag = "PlayerStats", coords = { x = 120.5, y = -45.2, z = 64.0 }, active_flags = { "bhop", "fast_duck", "anti_aim" }, enabled = true}
local json_str = json.pretty(payload)print(json_str)
local decoded = json.parse(json_str)print("Decoded Tag: " .. decoded.tag)print("Decoded Coord X: " .. decoded.coords.x)