analyse()
Diagnostic pass on invalid JSON — what failed and where.
Signature
php
JsonFast::analyse(string $json, ?int $output = OUTPUT_ARRAY): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | JSON text to analyse |
$output | ?int | OUTPUT_ARRAY | Output mode |
Returns
| Field | Type | Description |
|---|---|---|
valid | bool | Whether the input is valid JSON |
error | array | Present when invalid: message, line, column |
Example return value
php
// valid document
['valid' => true]
// invalid document
[
'valid' => false,
'error' => [
'message' => '...',
'line' => 3,
'column' => 18,
],
]Handle a failed import
php
$report = JsonFast::analyse($broken);
if ($report['valid']) {
$data = JsonFast::minify($broken);
} else {
throw new InvalidArgumentException(sprintf(
'JSON error at %d:%d — %s',
$report['error']['line'],
$report['error']['column'],
$report['error']['message']
));
}When to use
- Ingestion pipelines — log line and column when a feed fails validation
- User-facing uploads — show users where their JSON broke
- Partner integrations — richer error context than a boolean from
validate()
Related
inspect()— same error shape, lighter naming for quick checksvalidate()— boolean only