Skip to content

validate()

Fast boolean check — is the input valid JSON?

Signature

php
JsonFast::validate(string $json): bool

Parameters

NameTypeDescription
$jsonstringRaw JSON text to check

Returns

true if the document parses as valid JSON; false otherwise.

No error location or repair hints — use inspect() or analyse() when you need more detail.

Examples

php
JsonFast::validate('{"ok":true}');   // true
JsonFast::validate('{not json}');    // false
JsonFast::validate('');              // false

Gate processing without allocating a decoded structure:

php
if (!JsonFast::validate($payload)) {
    return response()->json(['error' => 'Invalid JSON'], 400);
}

$data = JsonFast::minify($payload);

Native tools, weird experiments, and practical performance work.