Skip to content

analyse()

Diagnostic pass on invalid JSON — what failed and where.

Signature

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

Parameters

NameTypeDefaultDescription
$jsonstringJSON text to analyse
$output?intOUTPUT_ARRAYOutput mode

Returns

FieldTypeDescription
validboolWhether the input is valid JSON
errorarrayPresent 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()

Native tools, weird experiments, and practical performance work.