PHPackages                             flavioheleno/jay - 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. flavioheleno/jay

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

flavioheleno/jay
================

Thin wrapper for json &amp; simdjson

2.0.1(1y ago)22411MITPHPPHP ^8.1CI passing

Since Mar 7Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/flavioheleno/jay)[ Packagist](https://packagist.org/packages/flavioheleno/jay)[ RSS](/packages/flavioheleno-jay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (5)Versions (8)Used By (1)

Jay
===

[](#jay)

Jay is a thin wrapper for json &amp; simdjson, allowing the fastest available json decoder to be used in a transparent way.

Under the hood, **Jay** will pick [simdjson](https://github.com/simdjson/simdjson) if available and the json encoded string is up to 4GiB (4.294.967.295 bytes), otherwise it will fallback to PHP's JSON Core Extension.

Extension support
-----------------

[](#extension-support)

This library should work with either option below:

- [crazyxman/simdjson\_php](https://github.com/crazyxman/simdjson_php) - Read only support
- [JakubOnderka/simdjson\_php](https://github.com/JakubOnderka/simdjson_php) - Read and write support

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

[](#installation)

To use Jay, simple run:

```
composer require flavioheleno/jay
```

Usage
-----

[](#usage)

This library usage is straightforward.

```
$jsonEncoded = '{"a":"b","c":true,"d":10}';

// before
$phpArray = json_decode($jsonEncoded, true);

// after
$phpArray = Jay\Json::fromString($jsonEncoded, true);
```

```
$phpArray = ['a' => 'b', 'c' => true, 'd' => 10];

// before
$jsonEncoded = json_encode($phpArray);

// after
$jsonEncoded = Jay\Json::toString($phpArray);
```

```
// before
$jsonEncoded = file_get_contents('path/to/file.json');
$phpArray = json_decode($jsonEncoded, true);

// after
$phpArray = Jay\Json::fromFile('path/to/file.json', true);
```

```
$phpArray = ['a' => 'b', 'c' => true, 'd' => 10];

// before
$jsonEncoded = json_encode($phpArray);
file_put_contents('path/to/file.json', $jsonEncoded);

// after
Jay\Json::toFile('path/to/file.json', $phpArray);
```

API
---

[](#api)

```
/**
 * @param string $filename   Name of the file to read.
 * @param bool $associative  When true, JSON objects will be returned as associative arrays; when false, JSON objects
 *                           will be returned as an instance of stdClass
 * @param int $depth Maximum nesting depth of the structure being decoded. The value must be greater than 0,
 *                           and less than or equal to 2.147.483.647
 *
 * @return mixed Returns the value encoded in JSON as an appropriate PHP type; unquoted values true, false and null
 *               are returned as true, false and null respectively
 *
 * @throws InvalidArgumentException If the $filename argument is not a file, is not readable, if the JSON cannot be
 *                                  decoded or if the encoded data is deeper than the nesting limit.
 * @throws RuntimeException         If the contents of $filename cannot be read.
 */
Jay\Json::fromFile(
  string $filename,
  bool $associative = false,
  int $depth = 512
): mixed;

/**
 * @param string $filename   Name of the file to write.
 * @param mixed $value       The value being encoded. Can be any type except a resource. All string data must be UTF-8
 *                           encoded.
 * @param int $flags         Bitmask consisting of JSON_FORCE_OBJECT, JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP,
 *                           JSON_HEX_APOS, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE,
 *                           JSON_NUMERIC_CHECK, JSON_PARTIAL_OUTPUT_ON_ERROR, JSON_PRESERVE_ZERO_FRACTION,
 *                           JSON_PRETTY_PRINT, JSON_UNESCAPED_LINE_TERMINATORS, JSON_UNESCAPED_SLASHES,
 *                           JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR.
 * @param int $depth Maximum nesting depth of the structure being encoded. The value must be greater than 0,
 *                           and less than or equal to 2.147.483.647
 *
 * @return int|false The number of bytes that were written to the file, or false on failure.
 *
 * @throws InvalidArgumentException If the $filename argument is not a writable file or if the JSON cannot be encoded
 *                                  or if the decoded data is deeper than the nesting limit.
 * @throws RuntimeException         If the encoded JSON cannot be write to $filename.
 */
Jay\Json::toFile(
  string $filename,
  mixed $value,
  int $flags = 0,
  int $depth = 512
): int|false;

/**
 * @param string|Stringable $contents The JSON string being decoded; this function only works with UTF-8 encoded
 *                                    strings.
 * @param bool $associative           When true, JSON objects will be returned as associative arrays; when false,
 *                                    JSON objects will be returned as an instance of stdClass
 * @param int $depth          Maximum nesting depth of the structure being decoded. The value must be greater
 *                                    than 0, and less than or equal to 2.147.483.647
 *
 * @return mixed Returns the value encoded in JSON as an appropriate PHP type; unquoted values true, false and null
 *               are returned as true, false and null respectively
 *
 * @throws InvalidArgumentException If the JSON cannot be decoded or if the encoded data is deeper than the nesting
 *                                  limit.
 */
Jay\Json::fromString(
  string|Stringable $contents,
  bool $associative = false,
  int $depth = 512
): mixed;

/**
 * @param mixed $value       The value being encoded. Can be any type except a resource. All string data must be UTF-8
 *                           encoded.
 * @param int $flags         Bitmask consisting of JSON_FORCE_OBJECT, JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP,
 *                           JSON_HEX_APOS, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE,
 *                           JSON_NUMERIC_CHECK, JSON_PARTIAL_OUTPUT_ON_ERROR, JSON_PRESERVE_ZERO_FRACTION,
 *                           JSON_PRETTY_PRINT, JSON_UNESCAPED_LINE_TERMINATORS, JSON_UNESCAPED_SLASHES,
 *                           JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR.
 * @param int $depth Maximum nesting depth of the structure being encoded. The value must be greater than 0,
 *                           and less than or equal to 2.147.483.647
 *
 * @return string A JSON encoded string.
 *
 * @throws InvalidArgumentException If the JSON cannot be encoded or if the decoded data is deeper than the nesting
 *                                  limit.
 */
Jay\Json::toString(
  mixed $value,
  int $flags = 0,
  int $depth = 512
): string;
```

License
-------

[](#license)

This library is licensed under the [MIT License](LICENSE).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance50

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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

Every ~130 days

Recently: every ~194 days

Total

7

Last Release

388d ago

Major Versions

0.3.0 → 1.0.02023-08-17

1.1.0 → 2.0.02025-04-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/42b9c9cbc06973a61587667fc811b853f4d71843f35ba2535f3900083e69ab3f?d=identicon)[flavioheleno](/maintainers/flavioheleno)

---

Top Contributors

[![flavioheleno](https://avatars.githubusercontent.com/u/471860?v=4)](https://github.com/flavioheleno "flavioheleno (18 commits)")

---

Tags

jsonsimdjsonjsonsimdjson

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/flavioheleno-jay/health.svg)

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15267.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

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