Syntax
json.getPath(object: table, path: string | table, defaultValue?: any): any | nilAliases
json.getpathArguments
| Name | Type | Description |
|---|---|---|
object | table | Object, table, or drawing value to inspect or change. |
path | string | table | Workspace-relative path to the file or folder. |
defaultValue? | any | Fallback value returned when the requested path is missing. |
Returns
| Name | Type | Description |
|---|---|---|
pathValue | any | nil | Value at the requested path, or the fallback value. |
Description
Reads a nested value from a table using a dotted path or path array.
Call it with 3 parameter(s): object, path, defaultValue. The argument table explains which values are required and which ones only refine the behavior.
It returns pathValue (any | nil). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Read a nested value with a fallback when the path is missing.
local document = {
user = {
profile = { name = "Guest" },
},
}
local name = json.getPath(document, { "user", "profile", "name" }, "Unknown")
print(name)