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

ActiveLibrary[API Development](/categories/api)

premiervirtual/json-api
=======================

Framework agnostic JSON API (jsonapi.org) implementation

v4.0.1(6y ago)01.7kApache-2.0PHPPHP &gt;=7.1.0

Since May 1Pushed 2y agoCompare

[ Source](https://github.com/TalentInc/json-api)[ Packagist](https://packagist.org/packages/premiervirtual/json-api)[ Docs](https://github.com/neomerx/json-api)[ RSS](/packages/premiervirtual-json-api/feed)WikiDiscussions v1.x Synced 2d ago

READMEChangelogDependencies (6)Versions (87)Used By (0)

[![Project Management](https://camo.githubusercontent.com/63ac17ae1fbd0235e8a27913843ab6ad454a14a972edf419bff7799e52d2fe11/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726f6a6563742d6d616e6167656d656e742d626c75652e737667)](https://waffle.io/neomerx/json-api)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f66943c28ae10dcbcf02fb187d53b86f200c1bb19cbbf15806d80e4db70cf4e5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f6a736f6e2d6170692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/3d13d1002763e74d3fe83c173d92483015004d75b0ed52656f27d2e4cdccf229/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f6a736f6e2d6170692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)[![Build Status](https://camo.githubusercontent.com/9c78128441ef4721739d0bc55197f640172e2587a8333befe9a7d46d57fc6eed/68747470733a2f2f7472617669732d63692e6f72672f6e656f6d6572782f6a736f6e2d6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/neomerx/json-api)[![HHVM](https://camo.githubusercontent.com/430e17d8c4240f59d616079c0cf6df930b06f84d615f40cf5c86a12eb8d3dafd/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f6e656f6d6572782f6a736f6e2d6170692e737667)](https://travis-ci.org/neomerx/json-api)[![License](https://camo.githubusercontent.com/749395c4ce36fed2206bf63c3d803b4a83d9592114908ace3dea4d292100f606/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e656f6d6572782f6a736f6e2d6170692e737667)](https://packagist.org/packages/neomerx/json-api)

Description
-----------

[](#description)

[![JSON API logo](https://camo.githubusercontent.com/5a13bdb171c3e1f6fc251a70f751b4b1957b598dd08dcf265ca7867fc1fef4b1/687474703a2f2f6a736f6e6170692e6f72672f696d616765732f6a736f6e6170692e706e67 "JSON API")](http://jsonapi.org/)

A good API is one of most effective ways to improve the experience for your clients. Standardized approaches for data formats and communication protocols increase productivity and make integration between applications smooth.

This framework agnostic package implements [JSON API](http://jsonapi.org/) specification **version v1.0** and helps focusing on core application functionality rather than on protocol implementation. It supports document structure, errors, data fetching as described in [JSON API Format](http://jsonapi.org/format/) and covers parsing and checking HTTP request parameters and headers. For instance it helps to correctly respond with `Unsupported Media Type` (HTTP code 415) and `Not Acceptable` (HTTP code 406) to invalid requests. You don't need to manually validate all input parameters on every request. You can configure what parameters are supported by your services and this package will check incoming requests automatically. It greatly simplifies API development and fully support specification. In particular

- Resource attributes and relationships
- Polymorphic resource data and relationships
- Compound documents with inclusion of related resources (circular resource references supported)
- Meta information for document, resources, errors, relationship and link objects
- Parsing HTTP `Accept` and `Content-Type` headers in accordance with [RFC 7231](https://tools.ietf.org/html/rfc7231)
- Parsing parameters for pagination, sorting and filtering
- Sparse fieldsets and customized included paths
- Errors

High code quality and **100% test coverage** with **250+ tests**. Production ready.

**To find out more, please check out the [Wiki](https://github.com/neomerx/json-api/wiki) and [Sample App](/sample)**.

> “I'm loving how easy it makes it to quickly implement an api”

–**Jeremy Cloutier**

Full-stack Integration
----------------------

[](#full-stack-integration)

This package is framework agnostic and if you are looking for practical usage sample you might be interested in Quick start JSON API server application [Limoncello App](https://github.com/limoncello-php/app).

The server supports

- CRUD operations for a few sample data models and Users.
- Cross-origin requests (CORS) to API server.
- Authentication (Bearer token) and authorizations for CRUD operations.
- Support for such JSON API features as resource inclusion, pagination and etc.

[![Demo app screen-shot](https://github.com/limoncello-php/app/raw/master/resources/img/screen-shot.png "Limoncello App")](https://github.com/limoncello-php/app)

Sample usage
------------

[](#sample-usage)

Assuming you've got an `$author` of type `\Author` you can encode it to JSON API as simple as this

```
$encoder = Encoder::instance([
    '\Author' => '\AuthorSchema',
], new EncoderOptions(JSON_PRETTY_PRINT, 'http://example.com/api/v1'));

echo $encoder->encodeData($author) . PHP_EOL;
```

will output

```
{
    "data": {
        "type": "people",
        "id": "123",
        "attributes": {
            "first_name": "John",
            "last_name": "Dow"
        },
        "links": {
            "self": "http://example.com/api/v1/people/123"
        }
    }
}
```

The `AuthorSchema` provides information about resource's attributes and might look like

```
class AuthorSchema extends SchemaProvider
{
    protected $resourceType = 'people';

    public function getId($author)
    {
        /** @var Author $author */
        return $author->authorId;
    }

    public function getAttributes($author)
    {
        /** @var Author $author */
        return [
            'first_name' => $author->firstName,
            'last_name'  => $author->lastName,
        ];
    }
}
```

The first `EncoderOptions` parameter `JSON_PRETTY_PRINT` is a PHP predefined [JSON constant](http://php.net/manual/en/json.constants.php).

The second `EncoderOptions` parameter `http://example.com/api/v1` is a URL prefix that will be applied to all encoded links unless they have `$treatAsHref` flag set to `true`.

**For more advanced usage please check out the [Wiki](https://github.com/neomerx/json-api/wiki)**.

Questions?
----------

[](#questions)

Do not hesitate to check [issues](https://github.com/neomerx/json-api/issues) or post a new one.

Need help?
----------

[](#need-help)

Are you planning to add JSON API and need help? We'd love to talk to you .

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

[](#contributing)

If you have spotted any specification changes that are not reflected in this package please post an [issue](https://github.com/neomerx/json-api/issues). Pull requests for documentation and code improvements are welcome.

Current tasks are managed with [Waffle.io](https://waffle.io/neomerx/json-api).

There are 2 ways to send pull requests

- small pull requests should be sent to `develop` branch as **1 commit**
- for bigger pull requests (e.g. new features) it's recommended to create an `issue` requesting a new branch for that feature. When a new branch named `feature/issueXX` is created (where `XX` is the issue number) you should post pull requests to this branch. When the feature is completed the branch will be squashed and merged to `develop` and then to `master` branches.

License
-------

[](#license)

Apache License (Version 2.0). Please see [License File](LICENSE) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 91.7% 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 ~39 days

Recently: every ~22 days

Total

83

Last Release

859d ago

Major Versions

v0.8.11 → v1.0.02017-02-17

v1.0.8 → v2.0.0-alpha2018-01-23

v1.0.9 → v2.0.22018-03-08

v2.0.7 → v3.0.0-rc.12019-01-26

v3.x-dev → v4.0.02019-10-20

PHP version history (3 changes)v0.1PHP &gt;=5.5.0

v2.0.0-alphaPHP &gt;=7.1.0

1.0.11PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1170038?v=4)[Dmytro Zasyadko](/maintainers/segoddnja)[@segoddnja](https://github.com/segoddnja)

---

Top Contributors

[![neomerx](https://avatars.githubusercontent.com/u/10420662?v=4)](https://github.com/neomerx "neomerx (266 commits)")[![lindyhopchris](https://avatars.githubusercontent.com/u/4464333?v=4)](https://github.com/lindyhopchris "lindyhopchris (8 commits)")[![segoddnja](https://avatars.githubusercontent.com/u/1170038?v=4)](https://github.com/segoddnja "segoddnja (6 commits)")[![LavaToaster](https://avatars.githubusercontent.com/u/838613?v=4)](https://github.com/LavaToaster "LavaToaster (3 commits)")[![boris-glumpler](https://avatars.githubusercontent.com/u/580004?v=4)](https://github.com/boris-glumpler "boris-glumpler (2 commits)")[![LiamKarlMitchell](https://avatars.githubusercontent.com/u/1968109?v=4)](https://github.com/LiamKarlMitchell "LiamKarlMitchell (1 commits)")[![hglattergotz](https://avatars.githubusercontent.com/u/506901?v=4)](https://github.com/hglattergotz "hglattergotz (1 commits)")[![lunika](https://avatars.githubusercontent.com/u/767834?v=4)](https://github.com/lunika "lunika (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![bravo-kernel](https://avatars.githubusercontent.com/u/230500?v=4)](https://github.com/bravo-kernel "bravo-kernel (1 commits)")

---

Tags

jsonapijsonapiJSON-APIneomerxjsonapi.org

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[neomerx/json-api

Framework agnostic JSON API (jsonapi.org) implementation

7433.7M30](/packages/neomerx-json-api)[cloudcreativity/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

7851.1M5](/packages/cloudcreativity-laravel-json-api)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.7M4](/packages/cloudcreativity-json-api-testing)[alsvanzelf/jsonapi

Human-friendly library to implement JSON:API without needing to know the specification.

55158.2k6](/packages/alsvanzelf-jsonapi)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.7k](/packages/nilportugues-jsonapi-bundle)[laravel-json-api/eloquent

Serialize Eloquent models as JSON:API resources.

121.5M7](/packages/laravel-json-api-eloquent)

PHPackages © 2026

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