PHP's JSON extension can tell you whether a string is valid JSON, but not whether that JSON has the right shape, with the expected fields and types. This RFC from Jakub Zelenka adds JSON Schema support to the JSON extension. JSON Schema is the most widely used way to describe what a JSON document should look like.
How it works
The RFC adds a JsonSchema class and a new $schema parameter on json_decode() and json_validate(). You build a schema with a static factory method. Here are the stubs from the RFC, trimmed:
class JsonSchemaException extends JsonException { } final class JsonSchema { private final function __construct() {} public static function createFromString(string $source): JsonSchema {} } function json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0, ?JsonSchema $schema = null): mixed {} function json_validate(string $json, int $depth = 512, int $flags = 0, ?JsonSchema $schema = null): bool {}
Some details from the RFC:
- Errors work like today. A schema failure is reported the same way as other JSON errors, either as a
JsonSchemaExceptionor as an error code fromjson_last_error(), andjson_last_error_msg()describes what went wrong. - New error constants. There are about 25 of them, all starting with
JSON_ERROR_SCHEMA_. - Supported drafts: draft-04, draft-06, draft-07, 2019-09 and 2020-12.
$schemais required. Your schema has to declare which draft it uses, though the author plans to make that optional later.
The validation code lives in a separate library, jso, which would be bundled with PHP. A working version already exists in the jsond PECL extension.
What might come later
The author says the bigger goal is what schemas could unlock. Ideas include mapping JSON directly into PHP classes, stopping a parse early once the data is known to be invalid, and better error locations. Each of these would need its own RFC.
What it means for existing code
According to the RFC, nothing breaks. The new parameter is optional and defaults to null.
Where it stands
The RFC is under discussion. It's at version 0.3, dated June 15, 2025, and targets PHP 8.6. The vote section still has placeholder dates, it needs a two-thirds majority to pass, and no vote has happened yet.
We list it as inactive because the page hasn't changed since June 2025 and no vote was ever held.