Added
-
fastjson_pointer_get(string $json, string $pointer, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed: read a single value from a JSON document by RFC 6901 JSON Pointer (/users/0/email; the empty pointer""selects the whole document). Only the referenced subtree is materialized into PHP. A missing path or malformed pointer returns null with the error state left clear (not a JSON error); a parse error returns null withfastjson_last_error()set, or throws underJSON_THROW_ON_ERROR.$associative,$depth, and$flags(includingFASTJSON_DECODE_RELAXED) matchfastjson_decode(). -
fastjson_merge_patch(string $target, string $patch, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed: apply an RFC 7386 JSON Merge Patch and return the merged document as a PHP value. Objects merge recursively, a non-object patch replaces the target wholesale, and anullmember deletes the corresponding key. Returns a PHP value (not a string) so output flows through the singlefastjson_encode()path — pass the result to it for byte-consistent JSON. A parse error in either operand returns null withfastjson_last_error()set, or throws underJSON_THROW_ON_ERROR. -
FASTJSON_DECODE_RELAXEDdecode flag: tolerate the JSONC subset thatext/jsonrejects — line (//) and block (/* */) comments, trailing commas, and a leading UTF-8 BOM. fastjson-only; there is noJSON_*counterpart. Well-formed JSON decodes identically with or without the flag. Pass it in$flags, e.g.fastjson_decode($jsonc, true, 512, FASTJSON_DECODE_RELAXED). Backed by yyjson'sALLOW_COMMENTS | ALLOW_TRAILING_COMMAS | ALLOW_BOMread flags, so parsing stays robust rather than relying on a pre-pass scrubber. -
PHP 8.1 support (lowered the minimum from 8.3).
-
fastjson_file_decode()andfastjson_file_encode(): read or write a JSON file in one call, collapsing thefastjson_decode(file_get_contents($f), ...)andfile_put_contents($f, fastjson_encode(...))patterns. Signatures mirror the in-memory functions, so$flagsand$depthbehave identically:fastjson_file_decode(string $filename, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedfastjson_file_encode(string $filename, mixed $value, int $flags = 0, int $depth = 512): bool
Both read and write through the PHP streams layer with the request default stream context, so stream wrappers,
open_basedir, andstream_context_set_default()apply, matchingfile_get_contents()/file_put_contents(). I/O failures are silent (no warning):fastjson_file_decode()returns null withfastjson_last_error()set,fastjson_file_encode()returns false. An empty file decodes likefastjson_decode("").JSON_THROW_ON_ERRORthrows on JSON parse/encode errors but not on filesystem errors. Implements php-src#22137.