Skip to content

Rust + PHP extension

php_jsonfast

Fast JSON parsing, repair, 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 — and handles malformed JSON that json_decode() rejects.

~3.3×faster diff vs native PHP
~9×faster schema vs Opis
~33 MB/srepair throughput (32 MB payload)
AnalyseGetting meaningful error messages from broken json strings

What can it do?

AnalyseSee exactly what is wrong, where, and which repair flags apply — before you touch the payload.
UnwrapPeel double- (or triple-) encoded JSON strings APIs and databases often return.
Auto RepairFix comments, JSONP, trailing commas, unquoted keys, and more.
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, repair with intent:

php
$broken = <<<'JSON'
{
    // user profile
    "name": Allan,
    "active": true,
}
JSON;

$report = JsonFast::analyse($broken);
// repairable: true, error at line 3, suggests REPAIR_COMMENTS + REPAIR_UNQUOTED_STRINGS

$flags = array_reduce(
    $report['repairs'],
    fn ($mask, $r) => $mask | $r['bit'],
    0
);

$fixed = JsonFast::repair($broken, $flags, JsonFast::OUTPUT_STRING);

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() tells you what to fix; unwrap() drills through layered string encoding — then repair, path, schema, merge, and diff live in the same API.

Start here

Repository: github.com/AllanGallop/libphp_jsonfast

Native tools, weird experiments, and practical performance work.