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

> Attempts to parse a JSON string like json.decodeSafe and returns status values for 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 to parse. The function reads this argument with string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. A boolean sets useNull. A table can set useNull and maxDepth.
  </ParamField>

  ## Returns

  <ResponseField name={"success"} type={"boolean"}>
    true when parsing succeeds, false when parsing fails inside the protected parse block.
  </ResponseField>

  <ResponseField name={"decoded"} type={"any | nil"}>
    Decoded value on success. On parse failure, this return is nil.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message on parse failure. The message is prefixed with json.decodeSafe and includes a near-position suffix.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position from the parser on parse failure. This return is only present on failure.
  </ResponseField>

  ## Types

  ### DecodeOptions

  Controls JSON parsing behavior.

  | Name       | Type      | Required | Description                                                           |
  | ---------- | --------- | -------- | --------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Represents JSON null with the library's null sentinel instead of nil. |
  | `maxDepth` | `integer` | No       | Sets the maximum nesting depth, clamped from 1 to 4096.               |

  ## Example

  Decode JSON with status returns using the 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>
