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

> Thu parse JSON string bang cung function nhu json.decodeSafe va tra ve status values cho parse errors.

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

  ## Đối số

  <ParamField path={"json"} type={"string"} required>
    JSON string de parse. Function doc argument nay bang string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. boolean dat useNull. table co the dat useNull va maxDepth.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"success"} type={"boolean"}>
    true khi parsing thanh cong, false khi parsing that bai trong protected parse block.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value khi success. Khi parse failure, return nay la nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message khi parse failure. Message duoc prefixed bang json.decodeSafe va co near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position tu parser khi parse failure. Return nay chi co khi failure.
  </ResponseField>

  ## Kiểu

  ### DecodeOptions

  Kiểm soát hành vi phân tích cú pháp JSON.

  | Name       | Type      | Required | Mô tả                                                                   |
  | ---------- | --------- | -------- | ----------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Biểu thị JSON null bằng giá trị null của thư viện thay vì con số không. |
  | `maxDepth` | `integer` | No       | Đặt độ sâu lồng tối đa, được kẹp từ 1 đến 4096.                         |

  ## Ví dụ

  Decode JSON voi status returns bang json.decodeSafe-compatible alias.

  ```lua theme={null}
  local ok, value, message, position = json.tryDecode('{"ready":true,"missing":null}', {
      useNull = true,
  })

  if ok then
      print(value.ready)
      print(json.isNull(value.missing))
  else
      warn(message, position)
  end
  ```
</div>
