PHPackages                             leeduc/json-api-builder - 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. leeduc/json-api-builder

ActiveLibrary

leeduc/json-api-builder
=======================

This package is auto generate data follow jsonapi.org.

v0.1.6(9y ago)6131MITPHPPHP ~5.5|~7.0

Since May 18Pushed 9y ago2 watchersCompare

[ Source](https://github.com/leeduc/json-api-builder)[ Packagist](https://packagist.org/packages/leeduc/json-api-builder)[ Docs](https://github.com/leeduc/json-api-builder)[ RSS](/packages/leeduc-json-api-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (8)Used By (0)

Json Api Builder
================

[](#json-api-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/023fbed96d98a86bca446a4ce3c5fef55976fc1cfb13cf749cac41bfb71ebbf5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65656475632f6a736f6e2d6170692d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeduc/json-api-builder)[![Build Status](https://camo.githubusercontent.com/1f43c1bb64765138fb05d76b8260ea80aa4f0eb40f49be1f0fc9887182782f67/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c65656475632f6a736f6e2d6170692d6275696c6465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/leeduc/json-api-builder)[![Coverage Status](https://camo.githubusercontent.com/b79d04c377cc3ee19787fabda63a87ebca5d31741c6fe2656b2c8cc14d995a37/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6c65656475632f6a736f6e2d6170692d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/leeduc/json-api-builder?branch=master)[![Total Downloads](https://camo.githubusercontent.com/61f8001099bb4a86e7959f91dbf2aee3504b6752ecbcc4db0d28c7481d8c04af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65656475632f6a736f6e2d6170692d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeduc/json-api-builder)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

This package is auto generate data follow jsonapi.org.

Install
-------

[](#install)

Via Composer

```
$ composer require leeduc/json-api-builder
```

Once this has finished, you will need to add the service provider to the providers array in your app.php config as follows:

```
'providers' => [
    // ...
    Leeduc\JsonApiBuilder\JsonApiBuilderServiceProvider::class,
]
```

Next, also in the app.php config file, under the aliases array, you may want to add facades.

```
'aliases' => [
    // ...
    'JsonApiBuilder' => Leeduc\JsonApiBuilder\Facades\JsonApiBuilder::class,
]
```

Usage
-----

[](#usage)

Build Schema in folder views of resource

`posts.view` = `app\resources\views\posts\show.schema.php`

```
return [
  'id' => $data->id,
  'type' => class_basename($data),
  'attributes' => [
    'name' => $data->name,
    'email' => $data->email
  ],
  'relationships' => [
    'posts' => [
      'partial' => 'posts.show',
      'links' => [
        'self' => route('get_user', ['id' => $data->id]) . '/relationships/posts',
        'related' => route('get_user', ['id' => $data->id]) . '/posts'
      ]
    ],
    'comments' => [
      'partial' => 'comments.show',
      'links' => [
        'self' => route('get_user', ['id' => $data->id]) . '/relationships/comments',
        'related' => route('get_user', ['id' => $data->id]) . '/comments'
      ]
    ]
  ],
  'links' => [
    'self' => route('get_user', ['id' => $data->id])
  ]
];
```

Build Array

```
$data = $users = User::with('comments')->paginate(10); // List
$data = $users = User::with('comments')->first(); // Object

$builder = \JsonApiBuilder::setData($data)
                    ->entity('view.path.name', function($data) {
                        $data['id'] = 100;
                        return $data;
                    })
                    ->relationship(['comments'])
                    ->included(['comments' => ['post_id', 'content']]);

dd($builder->parse()); // Array data
```

Build Json

```
$builder = \JsonApiBuilder::setData($data)
                    ->entity('package::view.path.name', function($data) {
                        // custom entity data
                        return $data;
                    })
                    ->relationship(['comments'])
                    ->included(['comments'])
                    ->json(['version' => '1.0'])
                    ->meta([
                      'version' => '1.0'
                    ])
                    ->pagination([
                      'next' => 'example/next',
                      'pre' => 'example/pre'
                    ])
                    ->response();

dd($builder); // Class Symfony\Component\HttpFoundation\Response
dd($builder->getContent()); // Get Json
```

Json response

```
{
  "data": [
    {
      "id": 1,
      "type": "user",
      "attributes": {
        "name": "Pj2EHmiLOH",
        "email": "Tqxfq6aZDk@gmail.com"
      },
      "links": {
        "self": "http://example.com/user\/1"
      },
      "relationships": {
        "comments": {
          "data": [
            {
              "id": 2,
              "type": "comment"
            },
            {
              "id": 8,
              "type": "comment"
            }
          ],
          "links": {
            "self": "http://example.com/user\/1\/relationships\/comments",
            "related": "http://example.com/user\/1\/comments"
          }
        }
      }
    }
  ],
  "included": [
    {
      "id": 2,
      "type": "comment",
      "attributes": {
        "post_id": "3",
        "user_id": "1",
        "content": "UHXLbmJxySxiTTYdjzR539bNXjohgpCVj0WfwvmZWKUonhUipxJeHPh0AtTWqIZpzLZfixawJJEQwqILf93Co5edPOrKDfaqvkSQ"
      },
      "relationships": {
        "user": {
          "data": [
            {
              "id": 1,
              "type": "user"
            }
          ],
          "links": {
            "self": "http://example.com/comment\/2\/relationships\/user"
          }
        }
      }
    },
    {
      "id": 8,
      "type": "comment",
      "attributes": {
        "post_id": "2",
        "user_id": "1",
        "content": "Y8kDX5EOQFtqoy4171bGFVNrvYgMRr9UVHQvD7Eed43YgzeZ1KFJipTFCMJVu6rtb4V8Fm14mv2t3aN26CRNgiOqDsGiMPbQyVJF"
      },
      "relationships": {
        "user": {
          "data": [
            {
              "id": 1,
              "type": "user"
            }
          ],
          "links": {
            "self": "http://example.com/comment\/8\/relationships\/user"
          }
        }
      }
    }
  ],
  "jsonapi": {
    "version": "1.0"
  },
  "links": {
    "self": "http://example.com/test",
    "first": "http://example.com/test?page%5Bsize%5D=1&page%5Bnumber%5D=1",
    "next": "http://example.com/test?page%5Bsize%5D=1&page%5Bnumber%5D=2",
    "last": "http://example.com/test?page%5Bsize%5D=1&page%5Bnumber%5D=40"
  }
}
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Le Duc](https://github.com/leeduc)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Total

6

Last Release

3592d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/19c3a5887dd2e682ce860f34527f438313a3bafe90f3865bb8f3dfdba843d8ae?d=identicon)[leeduc](/maintainers/leeduc)

---

Top Contributors

[![leeduc](https://avatars.githubusercontent.com/u/11553985?v=4)](https://github.com/leeduc "leeduc (30 commits)")

---

Tags

PhpSoftLeeducJsonApiBuilder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leeduc-json-api-builder/health.svg)

```
[![Health](https://phpackages.com/badges/leeduc-json-api-builder/health.svg)](https://phpackages.com/packages/leeduc-json-api-builder)
```

###  Alternatives

[laravel/sail

Docker files for running a basic Laravel application.

1.9k186.9M1.0k](/packages/laravel-sail)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[laravel/roster

Detect packages &amp; approaches in use within a Laravel project

15410.4M7](/packages/laravel-roster)

PHPackages © 2026

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