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

> พยายาม parse JSON string ด้วย function เดียวกับ json.decodeSafe และคืน status values สำหรับ parse errors.

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

  ## Arguments

  <ParamField path={"json"} type={"string"} required>
    JSON string ที่จะ parse. function อ่าน argument นี้ด้วย string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. boolean ตั้งค่า useNull. table ตั้งค่า useNull และ maxDepth ได้.
  </ParamField>

  ## Returns

  <ResponseField name={"success"} type={"boolean"}>
    true เมื่อ parsing สำเร็จ, false เมื่อ parsing ล้มเหลวใน protected parse block.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value เมื่อ success. เมื่อ parse failure return นี้เป็น nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message เมื่อ parse failure. Message มี prefix json.decodeSafe และมี near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position จาก parser เมื่อ parse failure. Return นี้มีเฉพาะตอน failure.
  </ResponseField>

  ## Types

  ### DecodeOptions

  ควบคุมพฤติกรรมการแยกวิเคราะห์ JSON

  | Name | Type | Required | คำอธิบาย |
  | - | - | - | - |
  | `useNull` | `boolean` | No | แสดงถึง JSON null ด้วย null sentinel ของไลบรารีแทนที่จะเป็น nil |
  | `maxDepth` | `integer` | No | ตั้งค่าความลึกของการซ้อนสูงสุด โดยยึดไว้ตั้งแต่ 1 ถึง 4096 |

  ## ตัวอย่าง

  Decode JSON พร้อม status returns โดยใช้ 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>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.