json. validate Synchronous
Check whether text is syntactically valid JSON without keeping a decoded value. Use this to accept or reject edited text before storing it.
Luau
json.validate(
text: string,
options: JsonDecodeOptions?
) -> (true) OR (false, message: string, position: number)Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | JSON document to check. |
options | JsonDecodeOptions? | Optional useNull boolean or options table. By default null becomes json.null and maxDepth is 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 for valid JSON; otherwise false, an error message, and its position.
Usage notes
Validation does not check application-specific field names or types. Bad argument types still raise an error.
Example
Luau
local ok, message, position = json.validate('{"enabled":true}')
if not ok then print(message, position) end
print(ok) -- true