json.encode and json.decode
Encode Lua values as JSON and decode JSON text into Lua values.
Syntax
ue.json.encode(value: any) -> string?, error?
ue.json.decode(text: string) -> any?, error?Supported values
JSON-compatible nil, booleans, numbers, strings, arrays, and string-keyed tables are supported. Tables may be nested up to 32 levels and cannot contain cycles.
Example
local text = assert(ue.json.encode({
name = "Rowan",
stats = { health = 100 },
tags = { "npc", "merchant" }
}))
local value = assert(ue.json.decode(text))
print(value.name, value.stats.health)Notes
- Lua strings are binary-safe, but JSON strings must contain valid JSON text when decoding.
- An empty Lua table has no key shape and is encoded as an empty JSON array.
- Unsupported userdata, functions, cyclic tables, invalid JSON, and excessive nesting return
nil, error.