PHPackages                             dmytrokucher/sift - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. dmytrokucher/sift

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

dmytrokucher/sift
=================

SIMD-accelerated JSON parsing for PHP via sonic-rs. Features lazy parsing, chainable Query API, and memory-efficient zero-copy parsing.

00PHP

Since Feb 3Pushed 3mo agoCompare

[ Source](https://github.com/kucherenkodmitriy/sift)[ Packagist](https://packagist.org/packages/dmytrokucher/sift)[ RSS](/packages/dmytrokucher-sift/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Sift (sonic-php)
================

[](#sift-sonic-php)

SIMD-accelerated JSON parsing for PHP via [sonic-rs](https://github.com/cloudwego/sonic-rs).

Features
--------

[](#features)

- **Lazy Parsing**: Extract specific values from massive JSON documents without full DOM construction
- **Query API**: Chainable, fluent interface that stays in Rust until hydration
- **SIMD Acceleration**: Uses modern CPU instructions for parallel JSON processing
- **Memory Efficient**: Zero-copy parsing minimizes allocations
- **Security Hardened**: Input size limits, depth limits, and overflow protection
- **PHP 8.x Compatible**: Works with PHP 8.1+

Requirements
------------

[](#requirements)

- PHP 8.1+ with development headers (`php-dev`)
- Rust 1.70+ (stable)
- Docker (recommended for development)

Installation
------------

[](#installation)

### Using Docker (Recommended)

[](#using-docker-recommended)

```
# Build and test in Docker
make docker-test

# Interactive development shell
make docker-shell
```

### Local Build

[](#local-build)

Requires PHP development headers installed:

```
# Ubuntu/Debian
sudo apt-get install php-dev

# Install cargo-php
cargo install cargo-php

# Build and install the extension
cargo php install --release

# Verify installation
php -m | grep sonic
```

### Composer (for IDE Support)

[](#composer-for-ide-support)

After installing the extension, add Composer support for IDE autocompletion:

```
composer require dmytrokucher/sift
```

This provides stub files for the `Sonic`, `Sift`, and `Query` classes, enabling full IDE autocompletion and type hints.

**Note**: Composer does not install the extension itself - you must build and install it first using one of the methods above.

API Reference
-------------

[](#api-reference)

### Legacy API (Sonic class)

[](#legacy-api-sonic-class)

#### `Sonic::get(string $json, string $pointer): mixed`

[](#sonicgetstring-json-string-pointer-mixed)

Extract a value by JSON pointer (RFC 6901) without full decode.

```
$json = '{"users": [{"id": 1, "email": "alice@example.com"}]}';

// Extract specific value - no full parsing needed
$email = Sonic::get($json, '/users/0/email');
// Returns: "alice@example.com"
```

#### `Sonic::decode(string $json): mixed`

[](#sonicdecodestring-json-mixed)

High-speed replacement for `json_decode()`.

```
$data = Sonic::decode('{"name": "sonic", "fast": true}');
// Returns: ["name" => "sonic", "fast" => true]
```

#### `Sonic::isValid(string $json): bool`

[](#sonicisvalidstring-json-bool)

SIMD-accelerated JSON validation.

```
if (Sonic::isValid($userInput)) {
    $data = Sonic::decode($userInput);
}
```

### Modern API (Sift class)

[](#modern-api-sift-class)

The `Sift` class provides the same methods as `Sonic`, plus the Query API.

#### `Sift::query(string $json): Query`

[](#siftquerystring-json-query)

Create a lazy Query object for chainable JSON navigation.

```
$json = '{"users": [{"id": 1, "email": "alice@example.com", "active": true}]}';

// Chainable navigation - stays in Rust until hydration
$email = Sift::query($json)
    ->get('users')
    ->index(0)
    ->get('email')
    ->string();
// Returns: "alice@example.com"
```

### Query API Methods

[](#query-api-methods)

#### Navigation (returns Query)

[](#navigation-returns-query)

MethodDescription`pointer(string $ptr)`Navigate using RFC 6901 JSON pointer`get(string $key)`Navigate into object by key`index(int $idx)`Navigate into array by index#### Hydration (extracts value)

[](#hydration-extracts-value)

MethodReturnsDescription`string()``string`Extract as string`int()``int`Extract as integer`float()``float`Extract as float`bool()``bool`Extract as boolean`value()``mixed`Full hydration to PHP array/value`raw()``string`Get raw JSON substring#### Type Checking

[](#type-checking)

MethodReturnsDescription`isNull()``bool`Check if value is null`isArray()``bool`Check if value is array`isObject()``bool`Check if value is object`getType()``string`Get type as string### Query Example

[](#query-example)

```
$json = '{"users": [{"id": 1, "profile": {"email": "alice@example.com"}}]}';

// Create query once, reuse for multiple extractions
$users = Sift::query($json)->get('users');

$email0 = $users->index(0)->get('profile')->get('email')->string();

// Using pointer syntax
$email = Sift::query($json)->pointer('/users/0/profile/email')->string();

// Type checking before extraction
$q = Sift::query($json)->pointer('/users/0');
if ($q->isObject()) {
    $user = $q->value();
}

// Get raw JSON without parsing
$rawUsers = Sift::query($json)->get('users')->raw();
// Returns: '[{"id": 1, "profile": {"email": "alice@example.com"}}]'
```

JSON Pointer Syntax
-------------------

[](#json-pointer-syntax)

JSON pointers follow RFC 6901:

PointerDescription`""`Root document`/foo`Key "foo" at root`/foo/0`First element of array "foo"`/foo/bar/baz`Nested path`/a~1b`Key "a/b" (escaped slash)`/a~0b`Key "a~b" (escaped tilde)Security
--------

[](#security)

Sift includes several security hardening measures:

ProtectionLimitDescriptionInput size64 MBMaximum JSON input sizeNesting depth512Maximum nesting depth (same as PHP's json\_decode)Pointer segments256Maximum path segments in pointersInteger overflowSafeLarge u64 values convert to float instead of overflowingNegative indicesRejectedNegative array indices return an errorBenchmarks
----------

[](#benchmarks)

Run benchmarks after installation:

```
make bench
```

### Expected Results

[](#expected-results)

Operationjson\_decodeSonic::decodeSonic::getFull decode (10K records)100ms45msN/AExtract single value100ms45ms5msMemory (50K records)150MB120MB1MB*Results vary by hardware and JSON structure*

Development
-----------

[](#development)

```
# Run all tests
make test

# Run PHP tests only (requires extension installed)
make test-php

# Run tests in Docker
make docker-test

# Format code
make fmt

# Lint code
make lint
```

Architecture
------------

[](#architecture)

See [ARCHITECTURE.md](docs/ARCHITECTURE.md) for details on:

- Memory management between PHP's Zend Arena and Rust's ownership model
- Query API lazy evaluation design
- SIMD optimization strategies
- Security measures and limits
- Error handling across the FFI boundary

Acknowledgements
----------------

[](#acknowledgements)

This project builds on excellent open-source libraries:

- [sonic-rs](https://github.com/cloudwego/sonic-rs) - The SIMD-accelerated JSON engine (Apache-2.0)
- [ext-php-rs](https://github.com/davidcole1340/ext-php-rs) - PHP/Rust bindings (MIT/Apache-2.0)

See [NOTICE](NOTICE) file for full attribution.

License
-------

[](#license)

MIT License - see LICENSE file for details.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance58

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4edb74ec7cd8936405ab3c6ad463e20acd48f2fc60e461a9ef38430ab18f842b?d=identicon)[kucherdmytro](/maintainers/kucherdmytro)

---

Top Contributors

[![kucherenkodmitriy](https://avatars.githubusercontent.com/u/7716481?v=4)](https://github.com/kucherenkodmitriy "kucherenkodmitriy (6 commits)")

### Embed Badge

![Health badge](/badges/dmytrokucher-sift/health.svg)

```
[![Health](https://phpackages.com/badges/dmytrokucher-sift/health.svg)](https://phpackages.com/packages/dmytrokucher-sift)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
