Skip to content

inspect()

Validation with error position — no repair suggestions.

Signature

php
JsonFast::inspect(string $json, ?int $output = OUTPUT_ARRAY): mixed

Parameters

NameTypeDefaultDescription
$jsonstringJSON text to inspect
$output?intOUTPUT_ARRAYOutput mode

Returns

Structure describing validity. When invalid, includes error line and column.

Typical array output:

php
// valid document
['valid' => true]

// invalid document
[
    'valid' => false,
    'error' => [
        'message' => '...',
        'line' => 3,
        'column' => 18,
    ],
]

When to use

NeedMethod
Pass/fail onlyvalidate()
Error location for logging or UIinspect()
Repair flags before fixinganalyse()

Examples

php
$report = JsonFast::inspect($upload);

if (!$report['valid']) {
    logger()->warning('JSON parse failed', [
        'line' => $report['error']['line'],
        'column' => $report['error']['column'],
        'message' => $report['error']['message'],
    ]);
}

API error response:

php
$report = JsonFast::inspect($body);

if (!$report['valid']) {
    return [
        'error' => 'invalid_json',
        'line' => $report['error']['line'],
        'column' => $report['error']['column'],
    ];
}

Native tools, weird experiments, and practical performance work.