Skip to content

Stdlib: json_validate() — validate JSON without full decode (PHP 8.3, ext/json parity) #3101

Description

@PurHur

Category

stdlib

Status (refreshed 2026-06-07 — implementation-ready)

Phase 0 landed: json_validate() is registered in ext/standard/Module.php; VM returns true/false for valid/invalid JSON via VmJsonScanner / ext/standard/json_validate.php.

Remaining gaps (worker targets):

Problem

PHP 8.3 added json_validate(string $json, int $depth = 512, int $flags = 0): bool. Phase 0 exists; behavior must match php-src for depth/ValueError and strict operand guards.

php-src reference

Repro (verify today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(json_validate(\"{\\\"a\\\":1}\")); echo PHP_EOL; var_export(json_validate(\"{\")); echo PHP_EOL;"
php bin/vm.php -r "var_export(json_validate(str_repeat(\"{\", 600)));" 2>&1 | head -1
'
Check Zend PHP 8.3+ VM (2026-06-07)
json_validate('{"a":1}') true true ✅
json_validate('{') false false ✅
depth exceeded ValueError verify / fix if diverges

Scope (this repo)

Path Work
ext/standard/json_validate.php Depth limit + flags (#4085)
ext/standard/VmJsonScanner.php Shared scanner with json_decode
JIT lib/JIT/Builtin/StringJson*.php when required
Tests test/compliance/cases/stdlib/json_validate*.phpt

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter json_validate'

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions