PHPackages                             snortlin/json-codec - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. snortlin/json-codec

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

snortlin/json-codec
===================

A PHP library for JSON encoding and decoding with adapter-based extensibility.

1.0.0(1mo ago)020MITPHPPHP ^8.5

Since Jul 3Pushed 1mo agoCompare

[ Source](https://github.com/snortlin/json-codec)[ Packagist](https://packagist.org/packages/snortlin/json-codec)[ RSS](/packages/snortlin-json-codec/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

snortlin/json-codec
===================

[](#snortlinjson-codec)

Small JSON encode/decode API for PHP.

The library provides simple `JsonEncoder` and `JsonDecoder` classes that hide the actual JSON implementation behind adapters.

It can automatically use a faster adapter when the supported PHP extension is available, or fall back to native PHP JSON functions.

Features
--------

[](#features)

- Simple JSON encode/decode API
- Static shortcut methods
- Instance-based usage suitable for DI
- Automatic adapter selection with native PHP fallback
- Custom encoder/decoder adapters
- Basic encode/decode context options

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

[](#installation)

```
composer require snortlin/json-codec
```

Supported adapters
------------------

[](#supported-adapters)

The default adapter factories select the best available adapter:

- `simdjson_encode()` / `simdjson_decode()` from [PECL simdjson](https://pecl.php.net/package/simdjson) or [awesomized/simdjson-plus-php-ext](https://github.com/awesomized/simdjson-plus-php-ext) (recommended)
- Native PHP `json_encode()` / `json_decode()`

If a supported simdjson extension is available, the simdjson adapter is used automatically. Otherwise, the native PHP adapter is used.

Encoding
--------

[](#encoding)

### Static API

[](#static-api)

```
use Snortlin\JsonCodec\JsonEncoder;

$json = JsonEncoder::json([
    'name' => 'John',
    'active' => true,
]);
```

### Instance API

[](#instance-api)

```
use Snortlin\JsonCodec\JsonEncoder;

$encoder = new JsonEncoder();

$json = $encoder->encode([
    'name' => 'John',
    'active' => true,
]);
```

### With options

[](#with-options)

```
use Snortlin\JsonCodec\JsonEncoder;

$json = JsonEncoder::json(
    data: ['name' => 'John'],
    context: [
        JsonEncoder::OPTIONS => JSON_PRETTY_PRINT,
        JsonEncoder::RECURSION_DEPTH => 512,
    ],
);
```

Decoding
--------

[](#decoding)

### Static API

[](#static-api-1)

```
use Snortlin\JsonCodec\JsonDecoder;

$data = JsonDecoder::array('{"name":"John","active":true}');
```

```
use Snortlin\JsonCodec\JsonDecoder;

$object = JsonDecoder::object('{"name":"John","active":true}');
```

### Instance API

[](#instance-api-1)

```
use Snortlin\JsonCodec\JsonDecoder;

$decoder = new JsonDecoder();

$data = $decoder->decode('{"name":"John","active":true}');
```

### With options

[](#with-options-1)

```
use Snortlin\JsonCodec\JsonDecoder;

$data = JsonDecoder::array(
    data: '{"name":"John"}',
    context: [
        JsonDecoder::RECURSION_DEPTH => 512,
    ],
);
```

```
use Snortlin\JsonCodec\JsonDecoder;

$data = (new JsonDecoder())->decode(
    data: '{"name":"John"}',
    context: [
        JsonDecoder::ASSOCIATIVE => true,
        JsonDecoder::RECURSION_DEPTH => 512,
    ],
);
```

Custom adapters
---------------

[](#custom-adapters)

Custom adapters can be passed directly to the API classes.

```
use Snortlin\JsonCodec\JsonEncoder;
use Snortlin\JsonCodec\Encoder\JsonEncoderAdapterInterface;

final class CustomEncoderAdapter implements JsonEncoderAdapterInterface
{
    public function encode(mixed $value, int $flags, int $depth): string
    {
        // Custom implementation
    }
}

$encoder = new JsonEncoder(
    encoder: new CustomEncoderAdapter(),
);
```

```
use Snortlin\JsonCodec\JsonDecoder;
use Snortlin\JsonCodec\Decoder\JsonDecoderAdapterInterface;

final class CustomDecoderAdapter implements JsonDecoderAdapterInterface
{
    public function decode(string $json, bool $associative, int $depth): mixed
    {
        // Custom implementation
    }
}

$decoder = new JsonDecoder(
    decoder: new CustomDecoderAdapter(),
);
```

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance90

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9af5cb9ca24e0eb3598369e199ab5ed10f1053f929da7d868da5f9fcb286d6af?d=identicon)[snortlin](/maintainers/snortlin)

---

Top Contributors

[![snortlin](https://avatars.githubusercontent.com/u/68695718?v=4)](https://github.com/snortlin "snortlin (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/snortlin-json-codec/health.svg)

```
[![Health](https://phpackages.com/badges/snortlin-json-codec/health.svg)](https://phpackages.com/packages/snortlin-json-codec)
```

###  Alternatives

[cybercog/laravel-paket

Composer personal web interface. Manage Laravel dependencies without switching to command line!

1763.3k](/packages/cybercog-laravel-paket)[serafim/properties

PHP properties implementation

769.1k1](/packages/serafim-properties)

PHPackages © 2026

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