{"id":18315536,"url":"https://github.com/mathieutu/laravel-json-syncer","last_synced_at":"2025-08-12T06:14:41.684Z","repository":{"id":52420554,"uuid":"99500349","full_name":"mathieutu/laravel-json-syncer","owner":"mathieutu","description":"A Json importer and exporter for Laravel.","archived":false,"fork":false,"pushed_at":"2024-07-10T04:16:18.000Z","size":72,"stargazers_count":28,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-11T04:01:07.209Z","etag":null,"topics":["database","eloquent","exporter","importer","json","laravel","php","syncer"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathieutu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-06T16:49:34.000Z","updated_at":"2024-03-20T10:04:36.000Z","dependencies_parsed_at":"2024-11-05T16:59:08.069Z","dependency_job_id":null,"html_url":"https://github.com/mathieutu/laravel-json-syncer","commit_stats":{"total_commits":38,"total_committers":6,"mean_commits":6.333333333333333,"dds":0.4473684210526315,"last_synced_commit":"09d871366c1d0891fda2c017d69f43ae61ad42f7"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mathieutu/laravel-json-syncer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Flaravel-json-syncer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Flaravel-json-syncer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Flaravel-json-syncer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Flaravel-json-syncer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathieutu","download_url":"https://codeload.github.com/mathieutu/laravel-json-syncer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathieutu%2Flaravel-json-syncer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270011192,"owners_count":24511902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","eloquent","exporter","importer","json","laravel","php","syncer"],"created_at":"2024-11-05T16:41:30.493Z","updated_at":"2025-08-12T06:14:41.645Z","avatar_url":"https://github.com/mathieutu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Json Syncer: Json importer and exporter for Laravel\n\n[![Github checks](https://img.shields.io/github/checks-status/mathieutu/laravel-json-syncer/main.svg?style=flat-square)](https://github.com/mathieutu/laravel-json-syncer/actions) \n[![Test coverage](https://img.shields.io/scrutinizer/coverage/g/mathieutu/laravel-json-syncer.svg?style=flat-square\u0026label=Coverage)](https://scrutinizer-ci.com/g/mathieutu/laravel-json-syncer/?branch=main) \n[![Code quality](https://img.shields.io/scrutinizer/g/mathieutu/laravel-json-syncer.svg?style=flat-square\u0026label=Quality)](https://scrutinizer-ci.com/g/mathieutu/laravel-json-syncer/?branch=main) \n[![Packagist downloads](https://img.shields.io/packagist/dt/mathieutu/laravel-json-syncer.svg?style=flat-square\u0026label=Downloads)](https://packagist.org/packages/mathieutu/laravel-json-syncer)\n[![Stable version](https://img.shields.io/packagist/v/mathieutu/laravel-json-syncer.svg?style=flat-square\u0026label=Packagist)](https://packagist.org/packages/mathieutu/laravel-json-syncer)\n\n## Installation\n\nRequire this package in your composer.json and update composer.\n```bash\ncomposer require mathieutu/laravel-json-syncer\n```\n\nAdd the `JsonExportable` and/or `JsonImportable` interfaces and `JsonExporter` and/or `JsonImporter` traits to your models.\n```php\nnamespace App\\Models;\n\n//...\nuse MathieuTu\\JsonSyncer\\Contracts\\JsonExportable;\nuse MathieuTu\\JsonSyncer\\Traits\\JsonExporter;\n// or/and\nuse MathieuTu\\JsonSyncer\\Contracts\\JsonImportable;\nuse MathieuTu\\JsonSyncer\\Traits\\JsonImporter;\n\nclass User extends Model implements JsonExportable, JsonImportable\n{\n    use JsonExporter;\n    use JsonImporter;\n    // ...\n}\n```\n\n## Configuration\n\nOut of the box, the Importer and Exporter will automatically guess what attributes and relations to handle, but you can customize everything:\n - JsonExporter:\n    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.\n    You can change that by setting the `$jsonExportableAttributes` and `$jsonExportableRelations` properties or overwriting the `getJsonExportableAttributes()` and `getJsonExportableRelations()` methods.\n\n - JsonImporter:\n    By default, it will import all the attributes which are in the `$fillable` properties and all the `HasOneOrMany` relations of your model.\n    You can change that by setting the `$jsonImportableAttributes` and `$jsonImportableRelations` properties or overwriting the `getJsonImportableAttributes()` and `getJsonImportableRelations()` methods.\n\n## Usage\n\nUse the `$model-\u003eexportToJson($jsonOptions = 0)` to export the object, all its attributes and its children (via its relations).\n\nUse `Model::importFromJson($objectsToCreate)` to import a json string or its array version.\n\n### Examples\n_(You can find all this examples in package tests)_\n\n#### How to export\nIf we consider this dataset in database :\n```json\n{\n    \"foos (Foo models)\": [{\n        \"id\": 1,\n        \"author\": \"Mathieu TUDISCO\",\n        \"username\": \"@mathieutu\",\n        \"bars (HasMany relation with Bar models)\": [\n            {\n                \"id\": 1,\n                \"name\": \"bar1\",\n                \"foo_id\": \"1\",\n                \"baz (HasOne relation with Baz model)\": {\n                    \"id\": 1,\n                    \"name\": \"bar1_baz\",\n                    \"bar_id\": \"1\"\n                }\n            },\n            {\n                \"id\": 2,\n                \"name\": \"bar2\",\n                \"foo_id\": \"1\",\n                \"baz (HasOne relation with Baz model)\": {\n                    \"id\": 2,\n                    \"name\": \"bar2_baz\",\n                    \"bar_id\": \"2\"\n                }\n            }\n        ]\n    }]\n}\n```\nWe can export it by:\n```php\nFoo::first()-\u003eexportToJson(JSON_PRETTY_PRINT);\n```\nIt will return:\n```json\n{\n    \"author\": \"Mathieu TUDISCO\",\n    \"username\": \"@mathieutu\",\n    \"bars\": [\n        {\n            \"name\": \"bar1\",\n            \"baz\": {\n                \"name\": \"bar1_baz\"\n            }\n        },\n        {\n            \"name\": \"bar2\",\n            \"baz\": {\n                \"name\": \"bar2_baz\"\n            }\n        }\n    ]\n}\n```\n\n#### How to import\nAnd exactly the same for the opposite. We can import the json returned by the previous method, or another one.\nFor the exact same app If we want to import this new very simple set of data:\n```json\n{\n    \"username\": \"@mathieutu\",\n    \"bars\": {\n        \"name\": \"my unique simple bar!\"\n    }\n}\n\n```\n\nWe can import it with:\n```php\nFoo::importFromJson($json);\n```\nAnd it will create all the entities in database:\n```php\ndd(Foo::with('bars.baz')-\u003efirst()-\u003etoArray());\n/*\narray:4 [\n  \"id\" =\u003e 1\n  \"author\" =\u003e null\n  \"username\" =\u003e \"@mathieutu\"\n  \"bars\" =\u003e array:1 [\n    0 =\u003e array:4 [\n      \"id\" =\u003e 1\n      \"name\" =\u003e \"my unique simple bar!\"\n      \"foo_id\" =\u003e \"1\"\n      \"baz\" =\u003e null\n    ]\n  ]\n]\n*/\n```\n\n### License\n\nThis JSON Syncer for Laravel is an open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n### Contributing\n\nIssues and PRs are obviously welcomed, as well for new features than documentation.\nEach piece of code added should be fully tested, but we can do that all together, so please don't be afraid by that. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieutu%2Flaravel-json-syncer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathieutu%2Flaravel-json-syncer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathieutu%2Flaravel-json-syncer/lists"}