PHPackages                             truschery/kanon - 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. truschery/kanon

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

truschery/kanon
===============

PHP implementation of JSON Canonicalization Scheme (RFC 8785)

v1.0.1(3mo ago)31171MITPHPPHP ^8.2CI passing

Since Mar 12Pushed 3mo agoCompare

[ Source](https://github.com/truschery/kanon)[ Packagist](https://packagist.org/packages/truschery/kanon)[ RSS](/packages/truschery-kanon/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (1)

JSON Canonicalization Scheme (RFC 8785) for PHP
===============================================

[](#json-canonicalization-scheme-rfc-8785-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a86475d2b1be8544a214eaf666d8bedffeccdc661e32ab62de626a7e13c36386/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7472757363686572792f6b616e6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/truschery/kanon)[![PHP from Packagist](https://camo.githubusercontent.com/9894a39e09e717fa37c8a98d1ea09adfa37423d9079ade023264e5e77f30e231/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7472757363686572792f6b616e6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/truschery/kanon)[![Total Downloads](https://camo.githubusercontent.com/c329eeee4175b2c92f147f6df0a1e547f9b00dd65b74a1d94e78c51e938ac298/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7472757363686572792f6b616e6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/truschery/kanon)[![Tests](https://camo.githubusercontent.com/adb775ca31f2c2e2117fcb2721fc618940cd93439ebec5b96c017d2dfd1b4c8f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7472757363686572792f6b616e6f6e2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/truschery/kanon/actions)[![License](https://camo.githubusercontent.com/43513d149890773c0526e774d6615c39cb8edd061e1791a8177a83034886e50a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7472757363686572792f6b616e6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/truschery/kanon)

A lightweight and strict PHP implementation of the **JSON Canonicalization Scheme (JCS)** according to [RFC 8785](https://datatracker.ietf.org/doc/html/rfc8785).

About the Specification
-----------------------

[](#about-the-specification)

JSON Canonicalization Scheme (RFC 8785) defines a standard way to serialize JSON data so that logically equivalent data produces identical byte-by-byte output. This is essential for creating digital signatures, hashing JSON payloads, or safely comparing JSON documents.

Key rules of JCS:

- Object properties are sorted lexicographically by their byte values.
- Whitespace between tokens is removed.
- Numbers are serialized in a strict format without trailing zeros.

⚠️ Important Note (PHP Configuration)
-------------------------------------

[](#️-important-note-php-configuration)

For this package to correctly serialize floating-point numbers according to the RFC requirements, your `php.ini` must have the `serialize_precision` directive set to `-1`.

Check your `php.ini` file:

```
serialize_precision = -1
```

*Note: In modern PHP versions (7.1+), `-1` is usually the default value, which ensures floats are encoded accurately.*

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

[](#installation)

You can install the package via Composer:

```
composer require truschery/kanon
```

Usage
-----

[](#usage)

Pass your array or object to the canonicalizer to get the RFC 8785 compliant JSON string.

```
use Truschery\Kanon\Json;

// Unordered array with different data types
$data =[
    'z' => 123.456,
    'a' => 'test',
    'b' =>[
        'foo' => 'bar',
        'baz' => 100
    ]
];

$canonicalJson = Json::canonicalize($data);

echo $canonicalJson;
// Output (keys sorted, no spaces):
// {"a":"test","b":{"baz":100,"foo":"bar"},"z":123.456}
```

Testing
-------

[](#testing)

This package comes with a test suite to ensure strict compliance with the specification. To run the tests, use:

```
composer test
# or directly:
./vendor/bin/phpunit
```

References
----------

[](#references)

- [RFC 8785: JSON Canonicalization Scheme (JCS)](https://datatracker.ietf.org/doc/html/rfc8785)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance81

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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 ~0 days

Total

2

Last Release

103d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.1

v1.0.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/466e6c0a3aa52012890dc8fed8ffa8ec1f94eeb49da030eff3c0784e60bf57be?d=identicon)[truschery](/maintainers/truschery)

---

Top Contributors

[![truschery](https://avatars.githubusercontent.com/u/204706577?v=4)](https://github.com/truschery "truschery (12 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/truschery-kanon/health.svg)

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[karriere/json-decoder

JsonDecoder implementation that allows you to convert your JSON data into PHP class objects

140439.4k12](/packages/karriere-json-decoder)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[json-mapper/laravel-package

The JsonMapper package for Laravel

25188.9k3](/packages/json-mapper-laravel-package)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)

PHPackages © 2026

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