inspect()
Validation with error position — no repair suggestions.
Signature
php
JsonFast::inspect(string $json, ?int $output = OUTPUT_ARRAY): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | JSON text to inspect |
$output | ?int | OUTPUT_ARRAY | Output 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
| Need | Method |
|---|---|
| Pass/fail only | validate() |
| Error location for logging or UI | inspect() |
| Repair flags before fixing | analyse() |
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'],
];
}Related
analyse()— addsrepairableand suggested flagsvalidate()— boolean only
