> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# json.getPath

> 使用 dotted string path 或 array table of keys 从 table 读取 nested value。

<div className="real-function-page">
  ```lua theme={null}
  json.getPath(object: table, path: string | table, defaultValue?: any): any | nil
  ```

  ## 别名

  * `json.getpath`

  ## 参数

  <ParamField path={"object"} type={"table"} required>
    要读取的 root table。function 要求这个 argument 是 table。
  </ParamField>

  <ParamField path={"path"} type={"string | table"} required>
    要跟随的 path。string 会按 dots split；integer string tokens 使用 raw array indexing 读取。table path 使用从 1 到 #path 的 array entries 作为 keys。
  </ParamField>

  <ParamField path={"defaultValue"} type={"any"}>
    当 traversal 在 path 完成前到达 nil 或 non-table 时返回的 fallback value。
  </ParamField>

  ## 返回值

  <ResponseField name={"pathValue"} type={"any | nil"}>
    Requested path 处的 value。如果 path missing，提供了 defaultValue 就返回它，否则返回 nil。
  </ResponseField>

  ## 示例

  从 dotted string path 或 array table of keys 读取 nested table value。

  ```lua theme={null}
  local document = {
      user = {
          profile = { name = "Guest" },
          items = { "first", "second" },
      },
  }

  local name = json.getPath(document, { "user", "profile", "name" }, "Unknown")
  local second = json.getPath(document, "user.items.2")

  print(name)
  print(second)
  ```
</div>
