Skip to content

0.4.0

Latest

Choose a tag to compare

@iliaal iliaal released this 12 Jun 01:00
· 3 commits to master since this release
0.4.0
105590b

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 with fastjson_last_error() set, or throws under JSON_THROW_ON_ERROR. $associative, $depth, and $flags (including FASTJSON_DECODE_RELAXED) match fastjson_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 a null member deletes the corresponding key. Returns a PHP value (not a string) so output flows through the single fastjson_encode() path — pass the result to it for byte-consistent JSON. A parse error in either operand returns null with fastjson_last_error() set, or throws under JSON_THROW_ON_ERROR.

  • FASTJSON_DECODE_RELAXED decode flag: tolerate the JSONC subset that ext/json rejects — line (//) and block (/* */) comments, trailing commas, and a leading UTF-8 BOM. fastjson-only; there is no JSON_* 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's ALLOW_COMMENTS | ALLOW_TRAILING_COMMAS | ALLOW_BOM read 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() and fastjson_file_encode(): read or write a JSON file in one call, collapsing the fastjson_decode(file_get_contents($f), ...) and file_put_contents($f, fastjson_encode(...)) patterns. Signatures mirror the in-memory functions, so $flags and $depth behave identically:

    • fastjson_file_decode(string $filename, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
    • fastjson_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, and stream_context_set_default() apply, matching file_get_contents()/file_put_contents(). I/O failures are silent (no warning): fastjson_file_decode() returns null with fastjson_last_error() set, fastjson_file_encode() returns false. An empty file decodes like fastjson_decode(""). JSON_THROW_ON_ERROR throws on JSON parse/encode errors but not on filesystem errors. Implements php-src#22137.