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

  ## Аргументы

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

  ## Возвраты

  <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 prefixed через json.decodeSafe и содержит near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position из parser при parse failure. Этот return есть только при failure.
  </ResponseField>

  ## Типы

  ### DecodeOptions

  Управляет поведением анализа JSON.

  | Name       | Type      | Required | Описание                                                                               |
  | ---------- | --------- | -------- | -------------------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Представляет значение JSON null с нулевым контрольным значением библиотеки вместо 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>
