PHPackages                             vrok/import-export - 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. [Database &amp; ORM](/categories/database)
4. /
5. vrok/import-export

ActiveLibrary[Database &amp; ORM](/categories/database)

vrok/import-export
==================

Helper to import from / export to JSON object graphs.

1.2.0(5mo ago)0671[1 PRs](https://github.com/j-schumann/import-export/pulls)MITPHPPHP ^8.3CI passing

Since Jan 27Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/j-schumann/import-export)[ Packagist](https://packagist.org/packages/vrok/import-export)[ Docs](https://vrok.de)[ RSS](/packages/vrok-import-export/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (7)Used By (0)

import-export
=============

[](#import-export)

Doctrine Helper to import from / export to JSON object graphs

[![CI Status](https://github.com/j-schumann/import-export/actions/workflows/ci.yaml/badge.svg)](https://github.com/j-schumann/import-export/actions)[![Coverage Status](https://camo.githubusercontent.com/e6da35325c428da0014636d1fdde1d249979ecc565a8d6d897f81c1e98ccf911/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a2d736368756d616e6e2f696d706f72742d6578706f72742f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/j-schumann/import-export?branch=main)

Uses Symfony's `PropertyAccess` to convert objects to arrays or generate objects from arrays. Which classes &amp; properties can be exported/imported (and how) can be controlled with the `ExportableProperty` and `ImportableProperty` PHP attributes: Only classes that have at least one `ExportableProperty` can be converted to array, only classes that have at least one `ImportableProperty` can be instantiated from array. Uses Doctrines `ClassUtils` to safely handle proxies.

Usage
-----

[](#usage)

Short Example, for more details see [ExportEntity](tests/Fixtures/ExportEntity.php)/ [ImportEntity](tests/Fixtures/ImportEntity.php) and [ExportHelperTest](tests/ExportHelperTest.php)/ [ImportHelperTest](tests/ImportHelperTest.php) for all features. Allows to export referenced entities (or only their identifiers) and collections.

```
use Vrok\ImportExport\ExportableProperty;
use Vrok\ImportExport\ExportHelper;
use Vrok\ImportExport\ImportableProperty;
use Vrok\ImportExport\ImportHelper;

class Entity
{
    #[ExportableProperty]
    #[ImportableProperty]
    public int $id = 0;

    #[ExportableProperty]
    #[ImportableProperty]
    public ?\DateTimeImmutable $timestamp = null;
}

$entity = new Entity();
$entity->id = 1;
$entity->timestamp = new \DateTimeImmutable();

$helper = new ExportHelper();
$export = $helper->objectToArray($entity);
$exportList = $helper->collectionToArray([$entity]);

/*
  $export === [
    'id'        => 1,
    'timestamp' => '2022-03-23....',
  ]
*/

$helper = new ImportHelper();
$newInstance = $helper->objectFromArray($export, Entity::class);
$newInstances = $helper->collectionFromArray([$export], Entity::class);
```

Features
--------

[](#features)

### Export

[](#export)

- can output object graphs, if a property pointing to another entity or DTO is marked with `ExportableProperty`
- can export an identifier, to be later mapped to the actual record, by using the `referenceByIdentifier` argument of the `ExportableProperty` attribute, e.g. instead of exporting the whole `User`, only it's ID could be exported for the `createdBy` property of another record.
- can export collections of objects (either by using `collectionToArray` or when a property is a Doctrine `Collection` or an array and marked with `asList`), even when they are of different types (e.g. through inheritance). An `_entityClass` field will contain the actual class.
- can limit exported data to only allowed properties by using the `propertyFilter` argument of `fromArray`
- can prevent (otherwise exportable property) from being exported by using the `propertyFilter` argument of `fromArray` and setting `isExcludeFilter` to `true`

### Import

[](#import)

- can reference existing records: if a property (collection or single object) points to an "importable entity" and the dataset contains an `int`/`string`the given `ObjectManager` is used to fetch the specified record from the database
- handle object graphs: ```
    {
      "name": "base entity",
      "nested": {
        "description": "for a property with type hint",
        "child": {
          "value": "for a property that is e.g. typed as an Interface",
          "_entityClass": "\\My\\DtoClass"
        }
      }
    }
    ```
- import only permitted fields (even when the dataset contains more, potentially importable properties) by using the `propertyFilter` argument of `fromArray`
- exclude fields from importing (even when they are in the dataset and potentially importable) by using the `propertyFilter` argument of `fromArray` and setting `isExcludeFilter` to `true`
- Automatically persists generated entities when they are marked for identity mapping, keeps an internal map of old ⇒ new identifiers. So when a reference from entity A to entity B is found in a later import object, the identity map is checked for matches, to update the reference to the new identifier.

Dependencies
------------

[](#dependencies)

- `doctrine/common` for the `ClassUtils` (proxy handling) and `Collection` properties
- `doctrine/persistence` for the `ObjectManager` (importing references)
- `symfony/property-access` for setting/reading (private, protected) properties
- dev: `symfony/uuid` for testing import of UUID values

Future Improvements
-------------------

[](#future-improvements)

- when only `doctrine/orm` ^4.0 is supported, remove the "if" in `AbstractOrmTestCase`
- what could be done with Symfony's serializer?
    - can already transform object (graphs) to array
    - properties can be marked with groups to be exportable
    - how to mark properties to only be exported as identifier? new attribute? how implement that, how is APIP doing this?
    - how to mark array properties to be treated as DTO-List?
    - how to ignore some properties without the need to hardcode groups? (exclude-filter)
    - how to limit to some properties without the need to hardcode groups? (include-filter)
- evaluate Doctrine's ORM collection attributes to check for allowed element class
- Improve union type handling (e.g. multiple base types: int|string)
- not only export to arrays but also directly to files
    - support exporting to multiple files (split to reduce size for large datasets)
- not only import from arrays but also directly from JSON files
    - support importing from multiple files (have been split to reduce size)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance76

Regular maintenance activity

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87% 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 ~103 days

Total

4

Last Release

165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed9373b6806c33f512ca3b63214dd2a2b2621bcbddffcdb99acc66ae7f0324aa?d=identicon)[j-schumann](/maintainers/j-schumann)

---

Top Contributors

[![j-schumann](https://avatars.githubusercontent.com/u/114239?v=4)](https://github.com/j-schumann "j-schumann (20 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (3 commits)")

---

Tags

jsonsymfonyexportdoctrineobject graphimport

###  Code Quality

TestsPHPUnit

Static AnalysisRector

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vrok-import-export/health.svg)

```
[![Health](https://phpackages.com/badges/vrok-import-export/health.svg)](https://phpackages.com/packages/vrok-import-export)
```

###  Alternatives

[sonata-project/doctrine-orm-admin-bundle

Integrate Doctrine ORM into the SonataAdminBundle

46117.7M155](/packages/sonata-project-doctrine-orm-admin-bundle)[portphp/portphp

Data import/export workflow

2702.9M22](/packages/portphp-portphp)[ddeboer/data-import

Import data from, and export data to, a range of file formats and media

5604.3M9](/packages/ddeboer-data-import)[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[doctrineencryptbundle/doctrine-encrypt-bundle

Encrypted symfony entity's by verified and standardized libraries

29415.1k](/packages/doctrineencryptbundle-doctrine-encrypt-bundle)[goodwix/doctrine-json-odm

JSON Object-Document Mapping bundle for Symfony and Doctrine

2226.0k](/packages/goodwix-doctrine-json-odm)

PHPackages © 2026

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