json. getPath Synchronous
json.getpath
Read a nested table value without writing a chain of nil checks. Use a dot path for ordinary field names, or an explicit key array when a key itself contains a dot.
Luau
json.getPath(value: Table, path: string | {any}, default: any?) -> anyParameters
| Parameter | Type | Description |
|---|---|---|
value | Table | Root table to inspect. |
path | string | {any} | Dot-separated path or an array of exact keys. Numeric-looking dot segments become numeric keys. |
default | any? | Value to return if a segment is missing; defaults to nil. |
Returns
anyThe value at the path, or the supplied default when it cannot be reached.
Usage notes
The function reads tables with rawget and does not invoke metamethods.
Example
Luau
local settings = { appearance = { theme = "dark" } }
print(json.getPath(settings, "appearance.theme", "light")) -- dark
print(json.getPath(settings, { "appearance", "scale" }, 1)) -- 1