analyse()
Diagnostic pass before repair — what failed, where, and which flags to apply.
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 already valid JSON |
repairable | bool | Whether repair() can fix it |
error | array | Present when invalid: message, line, column |
repairs | array | Suggested repair flags (see below) |
Each entry in repairs:
| Field | Description |
|---|---|
flag | Constant name (e.g. REPAIR_COMMENTS) |
bit | Numeric bitmask value |
description | Human-readable explanation |
Example return value
php
[
'valid' => false,
'repairable' => true,
'error' => [
'message' => '...',
'line' => 3,
'column' => 18,
],
'repairs' => [
[
'flag' => 'REPAIR_COMMENTS',
'bit' => 4,
'description' => 'Removes // and /* */ comments',
],
[
'flag' => 'REPAIR_UNQUOTED_STRINGS',
'bit' => 32,
'description' => 'Quotes unquoted string values',
],
],
]Build a targeted repair mask
php
$report = JsonFast::analyse($broken);
if ($report['valid']) {
$data = JsonFast::minify($broken);
} elseif (!$report['repairable']) {
throw new InvalidArgumentException($report['error']['message']);
} else {
$flags = array_reduce(
$report['repairs'],
fn ($mask, $r) => $mask | $r['bit'],
0
);
$data = JsonFast::repair($broken, $flags);
}When to use
- Ingestion pipelines where you want an audit trail of which repairs ran
- User-facing uploads — show line/column and whether auto-fix is possible
- Avoiding
REPAIR_ALLwhen only one or two issues are present
Related
repair()— apply flags from the reportinspect()— position only, no repair list- Repair constants
