PHPackages                             cameron1729/seb-json - 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. cameron1729/seb-json

ActiveLibrary

cameron1729/seb-json
====================

Encode PHP values as Safe Exam Browser SEB-JSON for Config Key generation.

v1.1.0(4w ago)036[4 issues](https://github.com/cameron1729/seb-json/issues)GPL-3.0-or-laterPHPPHP &gt;=8.1CI passing

Since Jul 11Pushed 4w agoCompare

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

READMEChangelog (5)Dependencies (6)Versions (7)Used By (0)

SEB-JSON
========

[](#seb-json)

[![CI](https://github.com/cameron1729/seb-json/actions/workflows/ci.yml/badge.svg)](https://github.com/cameron1729/seb-json/actions/workflows/ci.yml)[![SEB for Windows v3.10.2 / SEB for macOS 3.7](https://github.com/cameron1729/seb-json/actions/workflows/conformance.yml/badge.svg)](https://github.com/cameron1729/seb-json/actions/workflows/conformance.yml)[![PHP >=8.1](https://camo.githubusercontent.com/4cc99e4b10627fa5bb11782e3a51e7daace17a2107820826c485fd66d8ebb2c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e312d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/)[![Tests](https://camo.githubusercontent.com/4e46775a84165f62f5e2acf7e3357d180903fef80383fc7d515c6dc546e890af/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e69742d336639663366)](https://phpunit.de/)[![Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://github.com/cameron1729/seb-json/actions/workflows/ci.yml)[![Static Analysis](https://camo.githubusercontent.com/d2bd795cd86539c37fdeae87da97397df28b4a3458237975756be4b5ed5a5ee0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d326637346330)](https://phpstan.org/)[![Code Style](https://camo.githubusercontent.com/efd64deb9d65ebc0dadd2931c275544ada04b19d0c44c4e08b03e484a8f7b35c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5053522d2d31322d346331)](https://www.php-fig.org/psr/psr-12/)[![Licence](https://camo.githubusercontent.com/18433f64db6e6e501dc30458550734643cd3dc6223fef15cec5ea3e15ee5d274/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e63652d47504c2d2d332e302d2d6f722d2d6c617465722d626c7565)](LICENSE)

A small PHP encoder which converts native PHP data structures to Safe Exam Browser's JSON-ish serialisation format.

Unlike PHP's `json_encode`, this package produces strings using the byte representation expected by [Safe Exam Browser](https://safeexambrowser.org/) when calculating [Config Keys](https://safeexambrowser.org/developer/seb-config-key.html). It does not understand `.seb` configuration semantics and it does not canonicalise input: callers remain responsible for the shape and meaning of the value they pass to the encoder.

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

[](#installation)

```
composer require cameron1729/seb-json
```

Usage
-----

[](#usage)

```
use cameron1729\SebJson\SebJson;

$encoded = SebJson::encode([
    'browserMessagingSocket' => 'ws:\localhost:8706',
    'sendBrowserExamKey' => true,
]);
```

Output:

```
{"browserMessagingSocket":"ws:\localhost:8706","sendBrowserExamKey":true}

```

Why This Exists
---------------

[](#why-this-exists)

Safe Exam Browser does not hash ordinary JSON when calculating a Config Key. It hashes a deterministic, JSON-ish byte string commonly referred to as [SEB-JSON](https://safeexambrowser.org/developer/seb-config-key.html).

Despite its name, SEB-JSON is not standard JSON and is not necessarily valid JSON. Most importantly, SEB writes string contents without JSON character escaping. PHP's `json_encode` cannot be configured to do this: quotation marks, backslashes, and control characters are still escaped, changing the bytes that are ultimately hashed.

The [SEB Config Key documentation](https://safeexambrowser.org/developer/seb-config-key.html) explicitly says not to add character escaping. The [current SEB for Windows implementation](https://github.com/SafeExamBrowser/seb-win-refactoring/blob/v3.10.2/SafeExamBrowser.Configuration/ConfigurationData/Json.cs) does this literally: it writes a string by writing the opening quote, the raw string contents, and the closing quote.

For example, the PHP value:

```
$value = ['rule' => 'say "hello"'];
```

has these byte representations:

```
Standard JSON: {"rule":"say \"hello\""}
SEB-JSON:      {"rule":"say "hello""}

```

This distinction matters because Config Keys depend on the exact bytes. Even one additional backslash produces a different hash.

This package exists because implementations in other projects have repeatedly tried to produce SEB-JSON with ordinary JSON encoders, or by processing ordinary JSON output afterwards. That is easy to get subtly wrong. The encoder in this package is independently authored in PHP, with behaviour determined from the SEB documentation and official implementations. It remains limited to value encoding.

[MDL-78086](https://moodle.atlassian.net/browse/MDL-78086) documents one practical example in Moodle core. Moodle's SEB access rule currently uses `json_encode` with `JSON_UNESCAPED_SLASHES` and `JSON_UNESCAPED_UNICODE`. Those flags preserve forward slashes and characters outside ASCII such as `侃睦`. To preserve literal backslashes, Moodle uses an esoteric workaround where every backslash in a string value is replaced with `ؼҷҍԴ` before encoding, then that marker is changed back to a backslash afterwards (🙉). Quotes and control characters are still escaped normally, so the resulting bytes can still differ from the SEB-JSON bytes expected by Safe Exam Browser.

Other public implementations show the same trap:

- The [`certible/seb-node`](https://github.com/certible/seb-node/blob/main/src/config-key.ts) implementation notes that SEB says not to escape strings, but still uses `JSON.stringify` so that the output remains valid JSON
- The [`Chiogros/nSEA`](https://github.com/Chiogros/nSEA/blob/main/nsea.py) implementation uses Python's `json.dumps` and then removes spaces and newlines from the whole result, which still leaves JSON escaping and can alter whitespace inside setting values

Supported Values
----------------

[](#supported-values)

`SebJson::encode` accepts the following native PHP values:

- Associative arrays for SEB dictionaries
- Associative array keys are encoded in the order provided by the caller
- List arrays for SEB arrays
- Strings
- Integers from `-2147483648` through `2147483647`
- Finite floating point numbers, encoded using the invariant G15 format shared by the supported SEB releases
- Booleans

String values and string keys must contain valid UTF-8.

PHP objects, including `JsonSerializable` objects, are not accepted. Convert objects to plain arrays or scalar values before encoding.

This is intentional: SEB-JSON serialises property list values and does not define a general object serialisation mechanism comparable to PHP's `json_encode`.

Recursive PHP arrays are not accepted because SEB-JSON has no representation for references. Repeated references which do not form a cycle are encoded by value at each position.

Resources, `null`, integers outside the shared range, `NAN` and `INF` throw `InvalidArgumentException`.

`null` is intentionally rejected: it is not a property list value and the official Windows and macOS serialisers do not produce the same representation for it.

The currently supported Windows and macOS releases share an invariant G15 representation: up to 15 significant digits, scientific notation for decimal exponents below `-4` or at least `15`, and `0` for both positive and negative zero. This is an interim upstream compatibility rule. SEB's proposed move to RFC 8785 number formatting for SEB 4.0 remains tracked in [Safe Exam Browser issue #1495](https://github.com/SafeExamBrowser/seb-win-refactoring/issues/1495). Float output does not depend on PHP's `precision` setting.

PHP arrays cannot distinguish an empty list from an empty SEB dictionary, so `[]` is encoded as an empty list.

Out of Scope
------------

[](#out-of-scope)

This package deliberately does not:

- Parse `.seb` property list files
- Define the SEB configuration structure
- Decide which SEB settings should be included
- Sort associative array keys
- Remove `originatorVersion`
- Omit empty SEB dictionaries
- Calculate SHA-256 hashes
- Calculate Config Keys
- Calculate Browser Exam Keys

It only converts the PHP value it is given to SEB-JSON. For the meaning of SEB configuration structures, refer to the [Safe Exam Browser developer documentation](https://safeexambrowser.org/developer/) and [source code](https://github.com/SafeExamBrowser).

Compatibility
-------------

[](#compatibility)

### PHP and Moodle

[](#php-and-moodle)

The primary use case for this package is Moodle, but it works with any PHP project. Moodle is relevant to this compatibility policy only because its supported releases determine the oldest PHP version explicitly supported. This package supports every PHP minor from that version through the latest stable PHP release. The Moodle releases considered are those [still receiving general bug fixes](https://moodledev.io/general/releases#version-support), plus the newest released LTS. Other Moodle releases may continue to work, but are not part of the tested compatibility contract.

### Safe Exam Browser

[](#safe-exam-browser)

[Safe Exam Browser supports only its latest release and removes older releases after a grace period](https://safeexambrowser.org/download_releases_en.html). This package follows the same model for each platform and targets the latest stable releases of SEB for Windows and macOS. The versioned conformance badge identifies the exact releases currently verified.

The SEB-JSON encoding algorithm appears stable across other modern SEB releases, so other versions may also work. They are not part of this package's tested compatibility contract, and no compatibility guarantee is made for them.

`SebJson::encode` is an independent PHP implementation of the SEB-JSON value encoder. Automated conformance tests compare its output byte for byte with output from the official Windows and macOS serialisation code. Values on which the official implementations disagree are rejected, and new stable SEB releases become supported only after those tests pass.

Reference implementations:

- SEB for Windows v3.10.2:
- SEB for macOS 3.7:

This does not target older `seb-win` code paths that use .NET's [`JavaScriptSerializer`](https://learn.microsoft.com/en-us/dotnet/api/system.web.script.serialization.javascriptserializer.serialize?view=netframework-4.8.1), which produces ordinary JSON strings.

SEB-JSON should be treated as a byte serialisation format, not as ordinary JSON.

Licence
-------

[](#licence)

GPL-3.0-or-later.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.7% 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 ~5 days

Total

5

Last Release

29d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c1e8431d690d86fb0418272862fb070fbe5c3c0060d9ca393d14893e13d4d43?d=identicon)[cameron1729](/maintainers/cameron1729)

---

Top Contributors

[![cameron1729](https://avatars.githubusercontent.com/u/89116254?v=4)](https://github.com/cameron1729 "cameron1729 (14 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (5 commits)")

---

Tags

encodersebSafe Exam Browserseb-jsonconfig-key

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cameron1729-seb-json/health.svg)

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

###  Alternatives

[violet/streaming-json-encoder

Library for iteratively encoding large JSON documents piece by piece

3142.2M5](/packages/violet-streaming-json-encoder)[riimu/kit-phpencoder

Highly customizable alternative to var\_export for PHP code generation

718.6M38](/packages/riimu-kit-phpencoder)[miladrahimi/php-jwt

A PHP implementation of JWT (JSON Web Token) generator, parser, verifier, and validator

72286.3k2](/packages/miladrahimi-php-jwt)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6877.8k](/packages/sbsaga-toon)[dflydev/base32-crockford

Encode/decode numbers using Douglas Crockford's Base32 Encoding

14439.6k1](/packages/dflydev-base32-crockford)[renekorss/banklink

PHP banklink library to easily integrate Baltic banklinks.

3833.1k](/packages/renekorss-banklink)

PHPackages © 2026

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