PHPackages                             mathieutu/laravel-json-syncer - 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. mathieutu/laravel-json-syncer

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

mathieutu/laravel-json-syncer
=============================

Export and import your Eloquent models to/from JSON

1.5.0(2y ago)3033.1k↓81%6[1 PRs](https://github.com/mathieutu/laravel-json-syncer/pulls)MITPHPPHP &gt;=8.2

Since Aug 7Pushed 1y ago2 watchersCompare

[ Source](https://github.com/mathieutu/laravel-json-syncer)[ Packagist](https://packagist.org/packages/mathieutu/laravel-json-syncer)[ RSS](/packages/mathieutu-laravel-json-syncer/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (5)Versions (10)Used By (0)

Laravel Json Syncer: Json importer and exporter for Laravel
===========================================================

[](#laravel-json-syncer-json-importer-and-exporter-for-laravel)

[![Github checks](https://camo.githubusercontent.com/8be602b60ccebd8e182d94fe7db48a2f640b6d5caa96b19e2ff91d53f703dbde/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f6d61746869657574752f6c61726176656c2d6a736f6e2d73796e6365722f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/mathieutu/laravel-json-syncer/actions)[![Test coverage](https://camo.githubusercontent.com/5258990efae280b82f59944acc24514d776cf6d5613fd432e8c5ee6730f24704/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d61746869657574752f6c61726176656c2d6a736f6e2d73796e6365722e7376673f7374796c653d666c61742d737175617265266c6162656c3d436f766572616765)](https://scrutinizer-ci.com/g/mathieutu/laravel-json-syncer/?branch=main)[![Code quality](https://camo.githubusercontent.com/7af5fc81163eb510fda22a93c094442a003ccdaaaaeb505b3df0725146db8215/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d61746869657574752f6c61726176656c2d6a736f6e2d73796e6365722e7376673f7374796c653d666c61742d737175617265266c6162656c3d5175616c697479)](https://scrutinizer-ci.com/g/mathieutu/laravel-json-syncer/?branch=main)[![Packagist downloads](https://camo.githubusercontent.com/2027c1c24696771ffc2365a9933340d7b3be9f455f49ac99ca9b74298133c979/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61746869657574752f6c61726176656c2d6a736f6e2d73796e6365722e7376673f7374796c653d666c61742d737175617265266c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/mathieutu/laravel-json-syncer)[![Stable version](https://camo.githubusercontent.com/d5a25c40d898efca1d7e5f91f372d7e63b7d289da5e0ceccbc51ea3dec0215cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61746869657574752f6c61726176656c2d6a736f6e2d73796e6365722e7376673f7374796c653d666c61742d737175617265266c6162656c3d5061636b6167697374)](https://packagist.org/packages/mathieutu/laravel-json-syncer)

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

[](#installation)

Require this package in your composer.json and update composer.

```
composer require mathieutu/laravel-json-syncer
```

Add the `JsonExportable` and/or `JsonImportable` interfaces and `JsonExporter` and/or `JsonImporter` traits to your models.

```
namespace App\Models;

//...
use MathieuTu\JsonSyncer\Contracts\JsonExportable;
use MathieuTu\JsonSyncer\Traits\JsonExporter;
// or/and
use MathieuTu\JsonSyncer\Contracts\JsonImportable;
use MathieuTu\JsonSyncer\Traits\JsonImporter;

class User extends Model implements JsonExportable, JsonImportable
{
    use JsonExporter;
    use JsonImporter;
    // ...
}
```

Configuration
-------------

[](#configuration)

Out of the box, the Importer and Exporter will automatically guess what attributes and relations to handle, but you can customize everything:

- JsonExporter: By default, it will export all the attributes in the `$fillable` properties, except those with `*_id` pattern, and all the `HasOneOrMany` relations of your model. You can change that by setting the `$jsonExportableAttributes` and `$jsonExportableRelations` properties or overwriting the `getJsonExportableAttributes()` and `getJsonExportableRelations()` methods.
- JsonImporter: By default, it will import all the attributes which are in the `$fillable` properties and all the `HasOneOrMany` relations of your model. You can change that by setting the `$jsonImportableAttributes` and `$jsonImportableRelations` properties or overwriting the `getJsonImportableAttributes()` and `getJsonImportableRelations()` methods.

Usage
-----

[](#usage)

Use the `$model->exportToJson($jsonOptions = 0)` to export the object, all its attributes and its children (via its relations).

Use `Model::importFromJson($objectsToCreate)` to import a json string or its array version.

### Examples

[](#examples)

*(You can find all this examples in package tests)*

#### How to export

[](#how-to-export)

If we consider this dataset in database :

```
{
    "foos (Foo models)": [{
        "id": 1,
        "author": "Mathieu TUDISCO",
        "username": "@mathieutu",
        "bars (HasMany relation with Bar models)": [
            {
                "id": 1,
                "name": "bar1",
                "foo_id": "1",
                "baz (HasOne relation with Baz model)": {
                    "id": 1,
                    "name": "bar1_baz",
                    "bar_id": "1"
                }
            },
            {
                "id": 2,
                "name": "bar2",
                "foo_id": "1",
                "baz (HasOne relation with Baz model)": {
                    "id": 2,
                    "name": "bar2_baz",
                    "bar_id": "2"
                }
            }
        ]
    }]
}
```

We can export it by:

```
Foo::first()->exportToJson(JSON_PRETTY_PRINT);
```

It will return:

```
{
    "author": "Mathieu TUDISCO",
    "username": "@mathieutu",
    "bars": [
        {
            "name": "bar1",
            "baz": {
                "name": "bar1_baz"
            }
        },
        {
            "name": "bar2",
            "baz": {
                "name": "bar2_baz"
            }
        }
    ]
}
```

#### How to import

[](#how-to-import)

And exactly the same for the opposite. We can import the json returned by the previous method, or another one. For the exact same app If we want to import this new very simple set of data:

```
{
    "username": "@mathieutu",
    "bars": {
        "name": "my unique simple bar!"
    }
}
```

We can import it with:

```
Foo::importFromJson($json);
```

And it will create all the entities in database:

```
dd(Foo::with('bars.baz')->first()->toArray());
/*
array:4 [
  "id" => 1
  "author" => null
  "username" => "@mathieutu"
  "bars" => array:1 [
    0 => array:4 [
      "id" => 1
      "name" => "my unique simple bar!"
      "foo_id" => "1"
      "baz" => null
    ]
  ]
]
*/
```

### License

[](#license)

This JSON Syncer for Laravel is an open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

### Contributing

[](#contributing)

Issues and PRs are obviously welcomed, as well for new features than documentation. Each piece of code added should be fully tested, but we can do that all together, so please don't be afraid by that.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86% 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 ~370 days

Recently: every ~322 days

Total

7

Last Release

1031d ago

PHP version history (5 changes)1.0.0PHP &gt;=7.0

1.2.0PHP &gt;=7.2

1.2.1PHP &gt;=7.3

1.4.0PHP &gt;=7.4

1.5.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11351322?v=4)[Mathieu TUDISCO](/maintainers/mathieutu)[@mathieutu](https://github.com/mathieutu)

---

Top Contributors

[![mathieutu](https://avatars.githubusercontent.com/u/11351322?v=4)](https://github.com/mathieutu "mathieutu (37 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")[![joserick](https://avatars.githubusercontent.com/u/15143699?v=4)](https://github.com/joserick "joserick (2 commits)")[![rdarcy1](https://avatars.githubusercontent.com/u/15962421?v=4)](https://github.com/rdarcy1 "rdarcy1 (2 commits)")

---

Tags

databaseeloquentexporterimporterjsonlaravelphpsyncer

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mathieutu-laravel-json-syncer/health.svg)

```
[![Health](https://phpackages.com/badges/mathieutu-laravel-json-syncer/health.svg)](https://phpackages.com/packages/mathieutu-laravel-json-syncer)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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