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

> Parse JSON bang cung parser voi json.decode va tra ve success flag thay vi throw cho parse errors.

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

  ## Đối số

  <ParamField path={"json"} type={"string"} required>
    JSON text de parse. argument nay duoc kiem tra la string truoc khi parse errors duoc catch.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. boolean dat useNull truc tiep. table co the dat useNull va maxDepth; maxDepth duoc clamp tu 1 den 4096. Invalid option argument types duoc kiem tra truoc khi parse errors duoc catch.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"success"} type={"boolean"}>
    True khi parsing thanh cong, false khi parser bao error.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value khi thanh cong, nil khi parse failure. JSON false hop le tra ve success la true va decoded la false, vi vay hay kiem tra success return value.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message khi parse failure, nguoc lai nil. message bao gom json.decodeSafe prefix va parser position.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position khi parse failure, nguoc lai nil.
  </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ụ

  Parse JSON va dung success return value de tach valid false hoac nil results khoi parse failures.

  ```lua theme={null}
  local ok, value = json.decodeSafe("false")

  if ok then
      print(value == false)
  end

  local parsed, _, message, position = json.decodeSafe("{")
  if not parsed then
      warn(message, position)
  end
  ```
</div>
