PHPackages                             igorpocta/data-mapper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. igorpocta/data-mapper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

igorpocta/data-mapper
=====================

Lightweight PHP library for mapping data to objects and back (e.g. JSON ↔ object).

v1.9(2mo ago)21331MITPHPPHP ^8.1CI passing

Since Oct 30Pushed 2mo agoCompare

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

READMEChangelog (10)Dependencies (4)Versions (15)Used By (1)

Data Mapper
===========

[](#data-mapper)

[![CI](https://github.com/igorpocta/data_mapper/actions/workflows/ci.yml/badge.svg)](https://github.com/igorpocta/data-mapper/actions/workflows/ci.yml)[![PHP Version](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)](https://php.net)[![PHPStan Level](https://camo.githubusercontent.com/b72adb1f27170ecf486459c4b07e920bb3db2b464444bce8277e018270665646/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e)](https://phpstan.org)[![Tests](https://camo.githubusercontent.com/9bfb77b291889c29aab9e4196bfc55a66d45167c4d3297f31d8f0229e60b7cd6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d35393625323070617373696e672d73756363657373)](.)

High-performance and type-safe PHP library for bidirectional data mapping between JSON/arrays/CSV and objects.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer

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

[](#installation)

```
composer require igorpocta/data-mapper
```

Quick Start
-----------

[](#quick-start)

```
use Pocta\DataMapper\Mapper;

class User
{
    public function __construct(
        public int $id,
        public string $name,
        public bool $active
    ) {}
}

$mapper = new Mapper();

// JSON → Object
$user = $mapper->fromJson('{"id": 1, "name": "John", "active": true}', User::class);

// Object → JSON
$json = $mapper->toJson($user); // {"id":1,"name":"John","active":true}

// Array → Object
$user = $mapper->fromArray(['id' => 1, 'name' => 'John', 'active' => true], User::class);

// Object → Array
$array = $mapper->toArray($user); // ['id' => 1, 'name' => 'John', 'active' => true]
```

### Configuration

[](#configuration)

```
use Pocta\DataMapper\MapperOptions;

$mapper = new Mapper(MapperOptions::development()); // Strict validation for development
$mapper = new Mapper(MapperOptions::production());   // Lenient for production
$mapper = new Mapper(MapperOptions::strict());       // Both auto-validation and strict mode
```

Key Features
------------

[](#key-features)

### Mapping

[](#mapping)

- **Bidirectional mapping**: JSON/array/CSV ↔ objects with automatic conversion
- **CSV Support**: Import/export CSV files with automatic type conversion and custom column mapping
- **Batch processing**: Efficient mapping of collections with `fromArrayCollection()`, `toJsonCollection()`, `fromCsv()`, etc.
- **Property path resolver**: Map nested values using dot notation (e.g., `user.address.street`)
- **Type safety**: Full support for PHP 8.1+ types including union and intersection types

### Data Types

[](#data-types)

- **Basic types**: int, float, string, bool, array
- **DateTime**: DateTimeImmutable and DateTime with formats and timezones
- **Enum**: BackedEnum and UnitEnum (PHP 8.1+)
- **Objects**: Nested objects and arrays of objects

### Advanced

[](#advanced)

- **Constructor properties**: Full support for promoted properties
- **Partial updates**: Merge partial data into existing objects with `merge()`
- **Object-to-DTO mapping**: Map from Doctrine entities to DTOs using `fromObject()`
- **Discriminator mapping**: Polymorphic object mapping based on discriminator fields
- **Filters**: 70+ built-in filters (security, formatting, case conversion, etc.)
- **Hydration**: Custom functions for data transformation using `MapPropertyWithFunction`
- **Event System**: Hooks for pre/post processing (logging, transformations, error handling)
- **Validation**: 40+ Assert attributes (NotNull, Range, Email, Count, Valid, Callback, etc.)
- **Validation Groups**: Conditional validation with `GroupSequenceProviderInterface`
- **Recursive Validation**: `#[Valid]` for nested objects with dot-notation error paths

### Code Quality

[](#code-quality)

- **PHPStan Level 9**: Strictest static analysis
- **596 unit tests**, 1534 assertions
- **Zero external dependencies**
- **Debug &amp; Profiling**: Integrated tools for performance analysis

Documentation
-------------

[](#documentation)

TopicDescription[Configuration](docs/configuration.md)MapperOptions, supported types[Usage](docs/usage.md)Basic usage, batch processing, CSV, merge, Object-to-DTO, discriminator, class definitions[Advanced Features](docs/advanced.md)Property paths, filters, hydration, nullable, custom names, type conversion[Event System](docs/events.md)Event listeners, priorities, practical examples[Validation](docs/validation.md)Validators, groups, recursive validation, callback, custom validators[Cache System](docs/cache.md)Array, File, Redis, custom cache implementations[Debug &amp; Profiling](docs/debugging.md)Debugger, profiler, performance analysis[Architecture](docs/architecture.md)Custom types, separate components, folder structure, examplesTesting
-------

[](#testing)

```
# Run all tests
composer test

# Run PHPStan (level 9)
composer phpstan
```

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance85

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

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

Total

14

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7767e0ba6c49982f1045eae9d9e1157507789132da607f9c79a019879e4ed446?d=identicon)[igorpocta](/maintainers/igorpocta)

---

Top Contributors

[![igorpocta](https://avatars.githubusercontent.com/u/149055325?v=4)](https://github.com/igorpocta "igorpocta (46 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[nativephp/electron

Electron wrapper for the NativePHP framework.

519114.4k8](/packages/nativephp-electron)[kadet/keylighter

Yet another syntax highlighter for PHP

333.2k1](/packages/kadet-keylighter)[code16/formoj

Customizable form renderer

332.6k](/packages/code16-formoj)[nullthoughts/laravel-data-sync

Laravel utility to keep records synced between environments through source control

331.4k](/packages/nullthoughts-laravel-data-sync)

PHPackages © 2026

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