PHPackages                             carlonicora/jsonapi - 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. [API Development](/categories/api)
4. /
5. carlonicora/jsonapi

AbandonedLibrary[API Development](/categories/api)

carlonicora/jsonapi
===================

PHP library for {json:api} implementation

3.0.12(6y ago)21.7k1MITPHPPHP &gt;=8.0CI failing

Since May 10Pushed 4y ago2 watchersCompare

[ Source](https://github.com/carlonicora/jsonapi)[ Packagist](https://packagist.org/packages/carlonicora/jsonapi)[ Docs](https://carlonicora.com)[ RSS](/packages/carlonicora-jsonapi/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (48)Used By (1)

PHP library for {json:api}
==========================

[](#php-library-for-jsonapi)

[![Build Status](https://camo.githubusercontent.com/a1257f0b34ce7ee8228e75f4b91b6dafc23d07bf6b1714ff190d6f3623177a2b/68747470733a2f2f7472617669732d63692e636f6d2f6361726c6f6e69636f72612f6a736f6e6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/carlonicora/jsonapi)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![Coverage Status](https://camo.githubusercontent.com/782dc5f67f894355f2ab134c510b5419b077f5e44bc117585a8cf0eea37e28cf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6361726c6f6e69636f72612f6a736f6e6170692f62616467652e7376673f6272616e63683d646576)](https://coveralls.io/github/carlonicora/jsonapi?branch=dev)[![Maintainability](https://camo.githubusercontent.com/5ebfc708e7d979264c381407dcb8b814f09fafc092411c3bb15a419edf2291f6/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62373536356161383836326539346361646366352f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/carlonicora/jsonapi/maintainability)

JsonApi is a PHP library to manage [{json:api}](https://JsonApi.org) documents. The library also offers the possiblity to manage an http response directly from the library.

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

[](#installation)

**Composer**:

```
composer require carlonicora/jsonapi
```

**Git**:

```
git clone https://github.com/carlonicora/jsonapi.git
```

Config
------

[](#config)

The JsonApi library does not require any configuration.

Docker
------

[](#docker)

The library comes with a docker environment included. Useful for testing changes and running PHPUnit tests.

```
cd .docker
docker-compose build
docker-compose up -d
docker exec -ti jsonapi composer update
```

Usage
-----

[](#usage)

This library is organised around the objects identifiable in the [{json:api} documentation](https://jsonapi.org/format/).

### document

[](#document)

The main object is the `document` object, which gives you access to the main elements a {json:api} document can contain.

```
use \CarloNicora\JsonApi\document;

$document = new Document();
```

You can also import a {json:api} document from an array.

```
use \CarloNicora\JsonApi\Document;

$array = [
    'data' => [
        'type' => 'journal',
        'id' => 'andsjad897asd',
        'attributes' => [
            'title' => 'About phlow - the community media movement'
        ],
        'links' => [
            'self' => 'https://app.phlow.com/@carlo/journals/about-phlow-the-community-media-movement'
        ],
        'relationships' => [
            'author' => [
                'links' => [
                    'related' => 'https://app.phlow.com/@carlo'
                ],
                'data' => [
                    'type' => 'user',
                    'id' => 'adslau79ulaksdu',
                    'meta' => [
                        'isPrimaryAuthor' => true
                    ]
                ]
            ],
            'images' => [
                'data' => [
                    [
                        'type' => 'image',
                        'id' => '26037dd7-481b-4110-97f3-a879a08d1e20',
                        'meta' => [
                            'isCover' => true
                        ]
                    ],
                    [
                        'type' => 'image',
                        'id' => '2563cc0c-3202-4554-be70-3c9850d5369e',
                        'meta' => [
                            'isCover' => false
                        ]
                    ]
                ]
            ]
        ]
    ],
    'included' => [
        [
            'type' => 'user',
            'id' => 'adslau79ulaksdu',
            'attributes' => [
                'name' => 'Carlo Nicora',
                'username' => 'carlo',
                'url' => 'https://carlonicora.com'
            ],
            'meta' => [
                'hasJournals' => true,
                'hasPhotos' => true
            ],
            'links' => [
                'self' => 'https://app.phlow.com/@carlo'
            ]
        ],
        [
            'type' => 'image',
            'id' => '26037dd7-481b-4110-97f3-a879a08d1e20',
            'attributes' => [
                'url' => 'https://acc-phlow.imgix.net/wZaN92gl7WlRmDWrKp/26037dd7-481b-4110-97f3-a879a08d1e20.jpg?w=750&ixlib=js-1.1.0&s=28c961bf9a05855320fe853155b1cd7f'
            ],
            'links' => [
                'self' => 'https://acc-phlow.imgix.net/wZaN92gl7WlRmDWrKp/26037dd7-481b-4110-97f3-a879a08d1e20.jpg?w=750&ixlib=js-1.1.0&s=28c961bf9a05855320fe853155b1cd7f'
            ]
        ],
        [
            'type' => 'image',
            'id' => '2563cc0c-3202-4554-be70-3c9850d5369e',
            'attributes' => [
                'url' => 'https://acc-phlow.imgix.net/wZaN92gl7WlRmDWrKp/2563cc0c-3202-4554-be70-3c9850d5369e.jpg?w=750&ixlib=js-1.1.0&s=da188c73f2b571d1afd9b1625f482e05'
            ],
            'links' => [
                'self' => 'https://acc-phlow.imgix.net/wZaN92gl7WlRmDWrKp/2563cc0c-3202-4554-be70-3c9850d5369e.jpg?w=750&ixlib=js-1.1.0&s=da188c73f2b571d1afd9b1625f482e05'
            ]
        ]
    ]
];

$document = new Document($array);
```

### resourceObject

[](#resourceobject)

A `resourceObject` is a {json:api} document primary data. The `document` object can contain multiple `resourceObject`.

```
use \CarloNicora\JsonApi\Objects\ResourceObject;
use \CarloNicora\JsonApi\Objects\Link;

$resource = new ResourceObject('journal', 'iajhd80');

$resource->attributes->add('title', 'About phlow - the community media movement');
$resource->links->add(new Link('self', 'https://app.phlow.com/@carlo/journals/about-phlow-the-community-media-movement'));
```

As for the `document`, a `resourceObject` can be populated by passing an array.

```
use \CarloNicora\JsonApi\Objects\ResourceObject;

$array = [
    'type' => 'journal',
    'id' => 'andsjad897asd',
    'attributes' => [
        'title' => 'About phlow - the community media movement'
    ],
    'links' => [
        'self' => 'https://app.phlow.com/@carlo/journals/about-phlow-the-community-media-movement'
    ]
];

$resource = new ResourceObject(null, null, $array);
```

A `resourceObject` can contain multiple `relationship`, as defined in the {json:api} documentation.

```
use \CarloNicora\JsonApi\Objects\ResourceObject;

$resource = new ResourceObject('journal', '1');
$userResource = new ResourceObject('user', '10');

$resource->relationship('author')->resourceLinkage->add($userResource);
```

Versioning
----------

[](#versioning)

This project use [Semantic Versioning](https://semver.org/) for its tags.

Authors
-------

[](#authors)

- **Carlo Nicora** - Initial version - [GitHub](https://github.com/carlonicora) | [phlow](https://phlow.com/@carlo)

Contributions
-------------

[](#contributions)

Please, feel free to contribute, fork the repo and submit PR.

License
-------

[](#license)

This project is licensed under the [MIT license](https://opensource.org/licenses/MIT) - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

Established project with proven stability

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

Total

46

Last Release

2245d ago

Major Versions

1.0.5 → 2.0.02020-05-10

2.4.9 → 3.0.02020-05-10

PHP version history (4 changes)1.0.0PHP ^7.4

2.4.15PHP &gt;=7.4

3.0.0PHP &gt;=8

3.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb2d98115960a36e2eeea19879c25032b7780fbd834ed6951c086f17d1e7bf2b?d=identicon)[carlo.nicora](/maintainers/carlo.nicora)

---

Top Contributors

[![carlonicora](https://avatars.githubusercontent.com/u/63145?v=4)](https://github.com/carlonicora "carlonicora (60 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/carlonicora-jsonapi/health.svg)

```
[![Health](https://phpackages.com/badges/carlonicora-jsonapi/health.svg)](https://phpackages.com/packages/carlonicora-jsonapi)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k14](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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