Skip to content

json

The json namespace provides high-speed JSON encoding and decoding.


  • Numbers: Preserves integer vs float representations (e.g. 64 stays 64, not 64.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, and color serialize as null. Extract primitive coordinates/channels before stringifying.
  • Recursion Safety: Nested tables automatically halt at 32 recursion levels to prevent stack overflow.

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).

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)