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.

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

Parameters

Function parameters
ParameterTypeDescription
valueTableRoot table to search.
pathstring | {any}A path such as appearance.theme, or an array of keys for names containing dots or non-string keys.
defaultany?Value returned when the path is missing. Omission defaults to nil.

Returns

any

The value at the requested path, or the supplied default when the path is missing.

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