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

> Probuje parse JSON string ta sama function co json.decodeSafe i zwraca status values dla parse errors.

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

  ## Argumenty

  <ParamField path={"json"} type={"string"} required>
    JSON string do parse. Function czyta ten argument przez string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. boolean ustawia useNull. table moze ustawic useNull i maxDepth.
  </ParamField>

  ## Zwroty

  <ResponseField name={"success"} type={"boolean"}>
    true, gdy parsing sie powiedzie, false, gdy parsing zawiedzie w protected parse block.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value przy success. Przy parse failure ten return to nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message przy parse failure. Message jest prefixed przez json.decodeSafe i zawiera near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position z parser przy parse failure. Ten return wystepuje tylko przy failure.
  </ResponseField>

  ## Typy

  ### DecodeOptions

  Kontroluje zachowanie analizy JSON.

  | Name       | Type      | Required | Opis                                                                            |
  | ---------- | --------- | -------- | ------------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Reprezentuje JSON null ze wskaźnikiem null biblioteki zamiast nil.              |
  | `maxDepth` | `integer` | No       | Ustawia maksymalną głębokość zagnieżdżenia, zaciśniętą w zakresie od 1 do 4096. |

  ## Przykład

  Decode JSON ze status returns przez 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>
