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

> Versucht, einen JSON string mit derselben function wie json.decodeSafe zu parsen, und gibt status values fuer parse errors zurueck.

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

  ## Argumente

  <ParamField path={"json"} type={"string"} required>
    JSON string, der parsed wird. Die function liest dieses argument mit string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. Ein boolean setzt useNull. Eine table kann useNull und maxDepth setzen.
  </ParamField>

  ## Rückgaben

  <ResponseField name={"success"} type={"boolean"}>
    true, wenn parsing erfolgreich ist, false, wenn parsing im protected parse block fehlschlaegt.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value bei success. Bei parse failure ist dieser return nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message bei parse failure. Die message ist mit json.decodeSafe prefixed und enthaelt einen near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position aus dem parser bei parse failure. Dieser return ist nur bei failure vorhanden.
  </ResponseField>

  ## Typen

  ### DecodeOptions

  Steuert das JSON-Parsing-Verhalten.

  | Name       | Type      | Required | Beschreibung                                                                 |
  | ---------- | --------- | -------- | ---------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Stellt JSON Null mit dem Null-Sentinel der Bibliothek anstelle von Null dar. |
  | `maxDepth` | `integer` | No       | Legt die maximale Verschachtelungstiefe fest, geklemmt von 1 bis 4096.       |

  ## Beispiel

  Decode JSON mit status returns ueber den 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>
