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.

Syntax
Luau
json.getPath(value: Table, path: string | {any}, default: any?) -> any

Parameters

Function parameters
ParameterTypeDescription
valueTableRoot table to inspect.
pathstring | {any}Dot-separated path or an array of exact keys. Numeric-looking dot segments become numeric keys.
defaultany?Value to return if a segment is missing; defaults to nil.

Returns

any

The 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

Example
Luau
local settings = { appearance = { theme = "dark" } }
print(json.getPath(settings, "appearance.theme", "light")) -- dark
print(json.getPath(settings, { "appearance", "scale" }, 1)) -- 1
Kawaii documentation