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

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

psx/data
========

Data processing library to read and write POPOs in different formats

v7.1.1(2mo ago)4170.6k↓13.7%24Apache-2.0PHPPHP &gt;=8.0CI passing

Since Apr 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/apioo/psx-data)[ Packagist](https://packagist.org/packages/psx/data)[ Docs](https://phpsx.org)[ Fund](https://www.paypal.me/fusioapi)[ GitHub Sponsors](https://github.com/chriskapp)[ RSS](/packages/psx-data/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (18)Versions (49)Used By (4)

Data
====

[](#data)

Data processing library which helps to read and write data to and from POPOs in different formats.

Usage
-----

[](#usage)

The following example showcases how you could read/write a complex model.

```
// create processor
$processor = new Processor(Configuration::createDefault());

// example json data which we want to parse in our model
$in = getName();
$model->getComments()[0]->getText();

// writes the model back to json
$out = $processor->write(Payload::json($model));

// model classes
class News
{
    private ?int $id = null;
    private ?string $title = null;
    protected ?Author $author = null;
    /**
     * @var array|null
     */
    private ?array $comments = null;
     #[Format('date-time')]
    private ?string $date;

    // getter/setter implementations removed for readability
}

class Author
{
    private ?int $id = null;
    private ?string $name = null;
    private ?string $email = null;

    // getter/setter implementations removed for readability
}

class Comment
{
    private ?int $id = null;
    private ?Author $author = null;
    private ?string $text = null;

    // getter/setter implementations removed for readability
}
```

Formats
-------

[](#formats)

The library supports different reader and writer classes to produce different data formats. If you want to read a specific format you can provide the content type of the data. I.e. if you want read XML you could use the following payload:

```
$payload = Payload::create($in, 'application/xml');
```

The processor uses a reader factory to obtain the fitting reader for a specific content type. In this case it would use the XML reader. The reader factory can be easily extended with different reader classes to support other data formats.

```
$configuration->getReaderFactory()->addReader(new Acme\Reader(), 32);
```

In order to produce a payload from an incoming HTTP request you simply have to set the body as data and the content type from the header. How you access this data depends on the HTTP interface. For an PSR-7 request you could use:

```
$payload = Payload::create(
    (string) $request->getBody(),
    $request->getHeaderLine('Content-Type')
);
```

On the other hand if you want to write data as response you would use:

```
$payload = Payload::create(
    $model,
    $request->getHeaderLine('Accept')
);
```

The writer factory can also be extended with custom writer implementations.

```
$configuration->getWriterFactory()->addWriter(new Acme\Writer(), 64);
```

Transformations
---------------

[](#transformations)

Each reader class returns the data in a form which can be easily processed. I.e. the json reader returns a `stdClass` produced by `json_decode` and the xml reader returns a `DOMDocument`. To unify the output we use transformation classes which take the output of a reader and return a normalized format. I.e. for xml content we apply by default the `XmlArray` transformer which transforms the `DOMDocument`. So you can use a transformer if you directly want to work with the output of the reader.

In case you want to validate incoming XML data after a XSD schema you could use the `XmlValidator` transformer:

```
$payload = Payload::xml($data);
$payload->setTransformer(new XmlValidator('path/to/schema.xsd'));

$model = $processor->read(News::class, $payload);
```

Exporter
--------

[](#exporter)

If you write data you can set as payload an arbitrary object. We use an exporter class to return the actual data representation of that object. By default the exporter reads also the psx/schema attributes so you can use the same model for incoming and outgoing data. But it is also possible to use different classes. I.e. you could create model classes using the psx/schema attributes only for incoming data and for outgoing data you could use the JMS exporter in case you have already objects which have these annotations.

If you have another way how to extract data of an object (i.e. a toArray method which returns the available fields of the object) you can easily write a custom exporter.

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance84

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community14

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

Recently: every ~105 days

Total

48

Last Release

82d ago

Major Versions

v2.3.1 → v3.0.0-RC12020-07-24

3.x-dev → v4.0.02021-12-23

v4.0.5 → v5.0.02023-03-26

v5.0.1 → v6.0.02023-11-11

v6.0.4 → v7.0.02024-10-09

PHP version history (5 changes)v0.1.0PHP &gt;=5.5

v2.0.0PHP &gt;=5.6

v2.1.0PHP &gt;=7.0

v3.0.0-RC1PHP &gt;=7.2

v4.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2505846?v=4)[Christoph Kappestein](/maintainers/chriskapp)[@chriskapp](https://github.com/chriskapp)

---

Top Contributors

[![chriskapp](https://avatars.githubusercontent.com/u/2505846?v=4)](https://github.com/chriskapp "chriskapp (144 commits)")

---

Tags

jsonphppoposerializerxmljsonxmldataprocessorpopo

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psx/schema

Parse and generate data schema formats

57238.7k18](/packages/psx-schema)[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)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[samayo/country-json

A simple but useful data of the world (by country) in JSON formats

1.1k22.4k](/packages/samayo-country-json)[akrabat/rka-content-type-renderer

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

40443.2k1](/packages/akrabat-rka-content-type-renderer)

PHPackages © 2026

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