PHPackages                             exorg/data-coder - 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. exorg/data-coder

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

exorg/data-coder
================

Expansible Universal Data and Data Files Decoder/Encoder.

2.0.0(2y ago)0212[1 PRs](https://github.com/exorg/php-data-coder/pulls)MITPHPPHP 8.1 - 8.3

Since May 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/exorg/php-data-coder)[ Packagist](https://packagist.org/packages/exorg/data-coder)[ RSS](/packages/exorg-data-coder/feed)WikiDiscussions develop Synced 4w ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

DataCoder
=========

[](#datacoder)

[![example workflow](https://github.com/ExOrg/php-data-coder/actions/workflows/php.yml/badge.svg)](https://github.com/ExOrg/php-data-coder/actions/workflows/php.yml/badge.svg)

Extendable set of data and data file encoders and decoders. It allows to transfer PHP arrays into data strings and datafiles and vice versa with chosen format like YAML and JSON. It provides encapsulation of various decoding and encoding mechanisms, unifies interface and exceptions handling.

There are various groups of decoders and encoders

- With predefined data format - e.g. *Coder\\Json\\Data\\Decoder*, *Coder\\Yaml\\Datafile\\Encoder*
- With configurable data format - e.g. *Coder\\Data\\Decoder*, *Coder\\Datafile\\Encoder*
- For raw data - e.g. *Coder\\Json\\Data\\Decoder*, *Coder\\Data\\Encoder*
- For data in the file - e.g. *Coder\\Yaml\\Datafile\\Encoder*, *Coder\\Datafile\\Decoder*

Getting Started
---------------

[](#getting-started)

### Prerequisities

[](#prerequisities)

- [PHP](https://www.php.net/) 8.1 - 8.3
- [Git](https://git-scm.com/) 2.25.1+
- [Composer](https://getcomposer.org/) 2.6.0+

The instruction assumes using the Linux operating system or compatible tools for other operating systems.

### Installation

[](#installation)

#### php8.\*-cli, Git and Composer required

[](#php8-cli-git-and-composer-required)

The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org). [Git](https://git-scm.com/) is needed to fetch packages from version control repositories.

The *php8.\*-cli* is needed for installing Composer.

#### DataCoder installation

[](#datacoder-installation)

Add to your **composer.json** file appropriate entry by running the following command

```
composer require exorg/data-coder
```

If it's project set-up stage and no one dependency have been installed yet, run

```
composer install
```

If another dependencies have been intalled previously, run

```
composer update
```

Usage
-----

[](#usage)

The simplest way to autoload all needed files in executable file is attaching *autoload.php* file generated by Composer (after running `composer install` or `composer update` command) like in following example

```
require_once (__DIR__ . '/vendor/autoload.php');
```

### Data Encoders with predefined format

[](#data-encoders-with-predefined-format)

```
use ExOrg\DataCoder\Coder\Json\Data\Encoder;

$data = [
    "firstName" => "John",
    "lastName" => "Smith",
    "address" => [
        "streetAddress" => "21 2nd Street",
        "city" => "New York",
        "state" => "NY",
        "postalCode" => "10021-3100",
    ],
];

$encoder = new Encoder();
$result = $encoder->encodeData($data);

print($result);
```

---

```
{
    "firstName": "John",
    "lastName": "Smith",
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021-3100"
    }
}

```

### Data Decoders with predefined format

[](#data-decoders-with-predefined-format)

```
use ExOrg\DataCoder\Coder\Yaml\Data\Decoder;

$data = '
firstName: John
lastName: Smith
address:
  streetAddress: 21 2nd Street
  city: New York
  state: NY
  postalCode: 10021-3100
';

$decoder = new Decoder();
$result = $decoder->decodeData($data);

print_r($result);
```

---

```
Array
(
    [firstName] => John
    [lastName] => Smith
    [address] => Array
        (
            [streetAddress] => 21 2nd Street
            [city] => New York
            [state] => NY
            [postalCode] => 10021-3100
        )

)

```

### Data Encoder with configurable format

[](#data-encoder-with-configurable-format)

```
use ExOrg\DataCoder\Coder\Data\Encoder;

$data = [
    "firstName" => "John",
    "lastName" => "Smith",
    "address" => [
        "streetAddress" => "21 2nd Street",
        "city" => "New York",
        "state" => "NY",
        "postalCode" => "10021-3100",
    ],
];

$encoder = new Encoder();
$encoder->setDataFormat('yaml');
$result = $encoder->encodeData($data);

print($result);
```

---

```
firstName: John
lastName: Smith
address:
    streetAddress: '21 2nd Street'
    city: 'New York'
    state: NY
    postalCode: 10021-3100

```

### Data Decoder with configurable format

[](#data-decoder-with-configurable-format)

```
use ExOrg\DataCoder\Coder\Data\Decoder;

$data = '
{
    "firstName": "John",
    "lastName": "Smith",
    "isAlive": true,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021-3100"
    }
}
';

$decoder = new Decoder();
$decoder->setDataFormat('json');
$result = $decoder->decodeData($data);

print_r($result);
```

---

```
Array
(
    [firstName] => John
    [lastName] => Smith
    [isAlive] => 1
    [address] => Array
        (
            [streetAddress] => 21 2nd Street
            [city] => New York
            [state] => NY
            [postalCode] => 10021-3100
        )

)

```

### Datafile Encoders and Decoders

[](#datafile-encoders-and-decoders)

Datafile Encoders and Decoders usage is similar to the Data Encoders and Decoders. There are coders with predefined data format like **Coder\\Json\\Datafile\\Encoder** or **Coder\\Yaml\\Datafile\\Decoder** and those, where data format can be chosen by function *setDataFormat*, just like in examples above - **Code\\Datafile\\Encoder** and **Code\\Datafile\\Decoder**.

#### Data format recognizing by file extension

[](#data-format-recognizing-by-file-extension)

Datafile coders with configurable data format - **Coder\\Datafile\\Encoder** and **Coder\\Datafile\\Decoder** - can recognize data format by file extension. In that case, there is no need to set data format manually.

##### Datafile Encoder

[](#datafile-encoder)

```
use ExOrg\DataCoder\Coder\Datafile\Encoder;

$data = [
    "firstName" => "John",
    "lastName" => "Smith",
    "address" => [
        "streetAddress" => "21 2nd Street",
        "city" => "New York",
        "state" => "NY",
        "postalCode" => "10021-3100",
    ],
];

$datafilePath = 'data.json';

$encoder = new Encoder();
$encoder->encodeFile($data, $datafilePath);

print file_get_contents($datafilePath);
```

---

```
{
    "firstName": "John",
    "lastName": "Smith",
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021-3100"
    }
}

```

##### Datafile Decoder

[](#datafile-decoder)

```
use ExOrg\DataCoder\Coder\Datafile\Decoder;

$datafilePath = 'data.yaml';

print file_get_contents($datafilePath);

$decoder = new Decoder();
$data = $decoder->decodeFile($datafilePath);

print_r($data);
```

---

```
firstName: John
lastName: Smith
address:
    streetAddress: '21 2nd Street'
    city: 'New York'
    state: NY
    postalCode: 10021-3100
Array
(
    [firstName] => John
    [lastName] => Smith
    [address] => Array
        (
            [streetAddress] => 21 2nd Street
            [city] => New York
            [state] => NY
            [postalCode] => 10021-3100
        )

)

```

Tests
-----

[](#tests)

### Unit tests

[](#unit-tests)

This project has unit tests, which has been built with [PHPUnit](https://phpunit.de/) framework and run on Linux operating system.

To run tests, write the following command in your command line inside the main DataCoder project directory

```
vendor/bin/phpunit tests/
```

or use a Composer script

```
composer test
```

### Code style tests

[](#code-style-tests)

This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-12](http://www.php-fig.org/psr/psr-12/) standards.

To run tests for code style write the following command in your command line inside the main DataCoder project directory

```
vendor/bin/phpcs tests/ src/
```

or use a Composer script

```
composer sniff
```

You can also use a Composer script for running both tests and check code style

```
composer check
```

Built with
----------

[](#built-with)

- [Linux Mint](https://www.linuxmint.com/)
- [Visual Studio Code](https://code.visualstudio.com/)
- [Remarkable](https://remarkableapp.github.io/)
- [PHPUnit](https://phpunit.de/)
- [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
- [Composer](https://getcomposer.org/)
- [Git](https://git-scm.com/)
- [GitHub](https://github.com/)

Versioning
----------

[](#versioning)

This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags).

Contributing
------------

[](#contributing)

Please read [CONTRIBUTING.md](https://github.com/ExOrg/php-data-coder/blob/master/CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests.

Author
------

[](#author)

- **Katarzyna Krasińska** - [katheroine](https://github.com/katheroine), [ExOrg](https://github.com/ExOrg)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/ExOrg/php-data-coder/blob/master/LICENSE.md) file for details.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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

Total

2

Last Release

947d ago

Major Versions

1.0.0 → 2.0.02023-11-26

PHP version history (2 changes)1.0.0PHP &gt;=5.5.9

2.0.0PHP 8.1 - 8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3badf4e45129f57e587c47263f636b4f1954510d37e8b6db26ceef778e5834ee?d=identicon)[katheroine](/maintainers/katheroine)

---

Top Contributors

[![katheroine](https://avatars.githubusercontent.com/u/3116336?v=4)](https://github.com/katheroine "katheroine (246 commits)")

---

Tags

exorgencoderdecoderphp-data-coderdata-coder

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/exorg-data-coder/health.svg)

```
[![Health](https://phpackages.com/badges/exorg-data-coder/health.svg)](https://phpackages.com/packages/exorg-data-coder)
```

###  Alternatives

[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k45](/packages/friendsoftypo3-content-blocks)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[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).

6442.4k](/packages/sbsaga-toon)[shaarli/netscape-bookmark-parser

Generic Netscape bookmark parser

2545.7k](/packages/shaarli-netscape-bookmark-parser)[suin/json

A Simple wrapper of json\_decode() and json\_encode(). This provides object-oriented interface and exception-based error handing.

1027.6k3](/packages/suin-json)

PHPackages © 2026

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