> ## 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.parse

> 使用与 json.decode 相同的 function parse JSON string。

<div className="real-function-page">
  ```lua theme={null}
  json.parse(json: string, options?: DecodeOptions): any
  ```

  ## 参数

  <ParamField path={"json"} type={"string"} required>
    要 parse 的 JSON string。function 使用 string type checking 读取这个 argument。
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options。boolean 设置 useNull。table 可以设置 useNull 和 maxDepth。
  </ParamField>

  ## 返回值

  <ResponseField name={"decoded"} type={"any"}>
    Decoded value。JSON objects 和 arrays 会变成带有 JSON type markers 的 tables，strings 变成 Lua strings，numbers 变成 Lua numbers，booleans 变成 booleans，null 会变成 json.null，除非 useNull 为 false。
  </ResponseField>

  ## 类型

  ### DecodeOptions

  控制 JSON 解析行为。

  | Name       | Type      | Required | 说明                                 |
  | ---------- | --------- | -------- | ---------------------------------- |
  | `useNull`  | `boolean` | No       | 使用库的 null 标记而不是 nil 来表示 JSON null。 |
  | `maxDepth` | `integer` | No       | 设置最大嵌套深度，范围为 1 到 4096。             |

  ## 示例

  使用 json.decode 所用的相同 function parse JSON。

  ```lua theme={null}
  local settings = json.parse('{"volume":0.75,"theme":"dark","missing":null}', {
      useNull = true,
  })

  print(settings.volume)
  print(settings.theme)
  print(json.isNull(settings.missing))
  ```
</div>
