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

> Validate mot JSON string bang cach parse mot complete JSON value duy nhat. Khi success chi tra ve true. Khi parse failure tra ve false cong parser error details.

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

  ## Đối số

  <ParamField path={"json"} type={"string"} required>
    JSON string de validate. Function doc argument nay bang string type checking.
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options. boolean dat useNull. table co the dat useNull va maxDepth. maxDepth duoc clamp tu 1 den 4096.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"valid"} type={"boolean"}>
    true khi parsing mot complete JSON value duy nhat thanh cong. false khi parsing that bai trong protected parse block.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message khi parse failure. Message duoc prefixed bang json.validate va co near-position suffix. Return nay chi co khi failure.
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    Parser byte position tu parser khi parse failure. Return nay chi co khi failure.
  </ResponseField>

  ## Kiểu

  ### DecodeOptions

  Kiểm soát hành vi phân tích cú pháp JSON.

  | Name       | Type      | Required | Mô tả                                                                   |
  | ---------- | --------- | -------- | ----------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Biểu thị JSON null bằng giá trị null của thư viện thay vì con số không. |
  | `maxDepth` | `integer` | No       | Đặt độ sâu lồng tối đa, được kẹp từ 1 đến 4096.                         |

  ## Ví dụ

  Kiem tra mot string co chua dung mot complete JSON value hay khong.

  ```lua theme={null}
  print(json.validate('{"value":42}'))

  local valid, message, position = json.validate('{"value":42 trailing')

  if not valid then
      warn(message, position)
  end
  ```
</div>
