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

> JSON string を、1 つの complete JSON value として parse して検証します。success では true だけを返します。parse failure では false と parser error details を返します。

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

  ## 引数

  <ParamField path={"json"} type={"string"} required>
    validate する JSON string。function はこの argument を string type checking で読みます。
  </ParamField>

  <ParamField path={"options"} type={"DecodeOptions"}>
    Optional decode options。boolean は useNull を設定します。table は useNull と maxDepth を設定できます。maxDepth は 1 から 4096 に clamp されます。
  </ParamField>

  ## 戻り値

  <ResponseField name={"valid"} type={"boolean"}>
    1 つの complete JSON value の parsing が成功すると true。protected parse block 内で parsing が失敗すると false。
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    parse failure 時の Error message。message は json.validate で prefixed され、near-position suffix を含みます。この return は failure 時だけ存在します。
  </ResponseField>

  <ResponseField name={"errorPosition"} type={"number | nil"}>
    parse failure 時の parser からの Parser byte position。この return は failure 時だけ存在します。
  </ResponseField>

  ## 型

  ### DecodeOptions

  JSON 解析動作を制御します。

  | Name       | Type      | Required | 説明                                               |
  | ---------- | --------- | -------- | ------------------------------------------------ |
  | `useNull`  | `boolean` | No       | nil の代わりにライブラリの null センチネルを使用して JSON null を表します。 |
  | `maxDepth` | `integer` | No       | ネストの最大の深さを 1 ～ 4096 の範囲で設定します。                   |

  ## 例

  string がちょうど 1 つの 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>
