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

> يفسر JSON باستخدام نفس parser مثل json.decode ويعيد success flag بدلا من الرمي عند parse errors.

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

  ## الوسائط

  <ParamField path={"json"} type={"string"} required>
    JSON text للتفسير. يتم فحص هذا argument كـ string قبل catch لـ parse errors.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. قيمة boolean تضبط useNull مباشرة. table يمكن أن تضبط useNull و maxDepth؛ يتم clamp لـ maxDepth من 1 إلى 4096. Invalid option argument types يتم فحصها قبل catch لـ parse errors.
  </ParamField>

  ## القيم الراجعة

  <ResponseField name={"success"} type={"boolean"}>
    True عندما ينجح parsing، و false عندما يبلغ parser عن error.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value عند النجاح، و nil عند parse failure. JSON false صالح يعيد success كـ true و decoded كـ false، لذلك افحص success return value.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message عند parse failure، وإلا nil. الرسالة تتضمن json.decodeSafe prefix و parser position.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position عند parse failure، وإلا nil.
  </ResponseField>

  ## الأنواع

  ### DecodeOptions

  يتحكم في سلوك تحليل JSON.

  | Name       | Type      | Required | الوصف                                                 |
  | ---------- | --------- | -------- | ----------------------------------------------------- |
  | `useNull`  | `boolean` | No       | يمثل JSON null مع الحارس الفارغ للمكتبة بدلاً من صفر. |
  | `maxDepth` | `integer` | No       | يضبط الحد الأقصى لعمق التعشيش، المثبت من 1 إلى 4096.  |

  ## مثال

  Parse JSON واستخدم success return value لتمييز valid false أو nil results عن 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>
