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.

Syntax
Luau
json.validate(
    text: string,
    options: JsonDecodeOptions?
) -> (true) OR (false, message: string, position: number)

Parameters

Function parameters
ParameterTypeDescription
textstringJSON document to validate.
optionsJsonDecodeOptions?Optional boolean useNull flag or options table. Null preservation is enabled by default; maxDepth defaults to 256.

Argument fields

JsonDecodeOptions fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}
FieldDescription
useNullDefaults 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.
maxDepthMaximum 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

Example
Luau
local ok, message, position = json.validate('{"enabled":true}')
print(ok) -- true
Kawaii documentation