json. validate Synchronous
Check whether text is valid JSON without returning its decoded contents. Use it when you only need to accept or reject a document, such as before saving user-edited text. It checks syntax, not the names or types of application-specific fields.
Luau
json.validate(
text: string,
options: JsonDecodeOptions?
) -> (true) OR (false, message: string, position: number)Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | JSON document to validate. |
options | JsonDecodeOptions? | Optional boolean useNull flag or options table. Null preservation is enabled by default; maxDepth defaults to 256. |
Argument fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}| Field | Description |
|---|---|
useNull | Defaults to true, preserving JSON null as json.null. false converts null to nil, which can remove table entries. A boolean options argument is shorthand for this field. |
maxDepth | Maximum nesting depth. Defaults to 256; an integer is required and is clamped to 1–4096. |
Returns
(true) OR (false, message: string, position: number)true on success, or false followed by the parse message and position.
Usage notes
Invalid argument types still raise an error.
Example
Luau
local ok, message, position = json.validate('{"enabled":true}')
print(ok) -- true