Rust + PHP extension
php_jsonfast
Fast JSON parsing, path access, schema validation, merge/diff, and flexible output modes for PHP.
php_jsonfast is a PHP extension written in Rust. It returns native PHP arrays, compact JSON strings, or stdClass objects — with diagnostics, path access, and transforms beyond what json_decode() alone provides.
~3.3×faster diff vs native PHP
~9×faster schema vs Opis
~46 MB/smerge throughput (32 MB payload)
AnalyseGetting meaningful error messages from broken json strings
What can it do?
AnalyseSee exactly what is wrong and where — before you touch the payload.
UnwrapPeel double- (or triple-) encoded JSON strings APIs and databases often return.
Path accessRead dot paths and wildcards without full decode + manual walks.
SchemaInfer, validate, apply defaults — no extra Composer package.
TransformBeautify, minify, deep merge, and structural diff.
Tiny example
Diagnose first, then unwrap or parse:
php
$broken = <<<'JSON'
{
// user profile
"name": Allan,
"active": true,
}
JSON;
$report = JsonFast::analyse($broken);
// valid: false, error at line 3, column 12
if (!$report['valid']) {
throw new InvalidArgumentException(
"JSON error at {$report['error']['line']}:{$report['error']['column']}"
);
}When json_decode() returns a string instead of an array, the document is often wrapped twice:
php
$payload = '"{\"user\":{\"id\":42}}\"'; // string containing JSON
$data = JsonFast::unwrap($payload);
// ['user' => ['id' => 42]]The headline: stop guessing why JSON failed or how many times it was encoded.
analyse() pinpoints parse errors; unwrap() drills through layered string encoding — then path, schema, merge, and diff live in the same API. Start here
- Why JsonFast?
- Installation
- Quick start
- Examples
- Benchmarks
- API reference — one page per method
Repository: github.com/AllanGallop/libphp_jsonfast