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

> Validates a JSON string by parsing one complete JSON value. On success it returns only true. On parse failure it returns false plus parser error details.

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

  ## Arguments

  <ParamField path={"json"} type={"string"} required>
    JSON string to validate. 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. maxDepth is clamped from 1 to 4096.
  </ParamField>

  ## Returns

  <ResponseField name={"valid"} type={"boolean"}>
    true when parsing one complete JSON value succeeds. false when parsing fails inside the protected parse block.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error message on parse failure. The message is prefixed with json.validate and includes a near-position suffix. This return is only present on failure.
  </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

  Check whether a string contains exactly one complete JSON value.

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