json. getPath Synchronous
json.getpath
Read a nested table value using a dot-separated path or an array of explicit keys. Use it to read optional nested settings without a chain of nil checks. Pass explicit keys when a field name itself contains a dot.
Luau
json.getPath(value: Table, path: string | {any}, default: any?) -> anyParameters
| Parameter | Type | Description |
|---|---|---|
value | Table | Root table to search. |
path | string | {any} | A path such as appearance.theme, or an array of keys for names containing dots or non-string keys. |
default | any? | Value returned when the path is missing. Omission defaults to nil. |
Returns
anyThe value at the requested path, or the supplied default when the path is missing.
Example
Luau
local settings = { appearance = { theme = "dark" } }
print(json.getPath(settings, "appearance.theme", "light")) -- dark
print(json.getPath(settings, { "appearance", "scale" }, 1)) -- 1