Skip to content

schemaDiff()

Diff two JSON Schema documents.

Signature

php
JsonFast::schemaDiff(
    string $beforeSchema,
    string $afterSchema,
    ?int $output = OUTPUT_ARRAY
): mixed

Parameters

NameTypeDefaultDescription
$beforeSchemastringOriginal schema JSON
$afterSchemastringUpdated schema JSON
$output?intOUTPUT_ARRAYOutput mode

Returns

Structural difference between the two schemas — same general shape as diff() (added, removed, changed with JSON Pointer-style paths).

Use when reviewing API version bumps or generating changelog entries for contract changes.

Examples

Compare v1 and v2 API schemas:

php
$changes = JsonFast::schemaDiff(
    file_get_contents('schemas/v1.json'),
    file_get_contents('schemas/v2.json')
);

if (!empty($changes['removed'])) {
    notifyBreakingChange($changes['removed']);
}

CI check — schema must not drift unexpectedly:

php
$drift = JsonFast::schemaDiff($committedSchema, $generatedSchema);
assert(empty($drift['added']) && empty($drift['removed']) && empty($drift['changed']));

Native tools, weird experiments, and practical performance work.