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

ActiveLibrary[API Development](/categories/api)

art4/json-api-client
====================

JSON API client

1.3.0(1y ago)139804.8k↓52.4%21[5 issues](https://github.com/Art4/json-api-client/issues)[1 PRs](https://github.com/Art4/json-api-client/pulls)8GPL-3.0-or-laterPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0CI passing

Since Aug 11Pushed 9mo ago11 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (25)Used By (8)

JsonApiClient
=============

[](#jsonapiclient)

[![Latest Version](https://camo.githubusercontent.com/502cd697626a52b5b2aceb5705f1a94dcc8eadc4070496c0781894da25d8a965/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f417274342f6a736f6e2d6170692d636c69656e742e737667)](https://github.com/Art4/json-api-client/releases)[![Software License](https://camo.githubusercontent.com/6f2b03e518f71117284f01a8bf089395fa6c9400661b197d9b9be1919550b944/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c332d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/art4/json-api-client/actions/workflows/unit-tests.yml/badge.svg?branch=v1.x)](https://github.com/Art4/json-api-client/actions)[![codecov](https://camo.githubusercontent.com/0b50e236f9e77d2f8aa1320f71ce97a01fed1a715cc22c6b973c228c1686cccd/68747470733a2f2f636f6465636f762e696f2f67682f417274342f6a736f6e2d6170692d636c69656e742f67726170682f62616467652e7376673f746f6b656e3d356f4e4e44455557675a)](https://codecov.io/gh/Art4/json-api-client)[![Total Downloads](https://camo.githubusercontent.com/8ee2e284bd804d46ecdaa1c25caffe40c7b67118405cf7a663f95f809c78e445/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617274342f6a736f6e2d6170692d636c69656e742e737667)](https://packagist.org/packages/art4/json-api-client)

JsonApiClient 👷‍♀️ is a PHP Library to validate and handle the response body from a [JSON API](http://jsonapi.org) Server.

Format: [JSON API 1.0](http://jsonapi.org/format/1.0/)

🏁 Goals
-------

[](#checkered_flag-goals)

- ✅ Be 100% JSON API 1.0 spec conform
- ⬜ Be open for new spec minor versions (see [\#90](https://github.com/Art4/json-api-client/issues/90))
- ✅ Handle/validate a server response body
- ✅ Handle/validate a client request body
- ✅ Offer an easy way to retrieve the data
- ✅ Allow extendability and injection of classes/models

📦 Install
---------

[](#package-install)

Via Composer

```
$ composer require art4/json-api-client
```

### 🏗️ Upgrade to v1

[](#building_construction-upgrade-to-v1)

**Version 1.0 is finally released.** 🎉

After version 0.8.0 there where no breaking changes. Every change was backward compatible and every functionality that was removed in v1.0 only triggers a deprecation warning in v0.10.

To upgrade from v0.x to v1 just update to 0.10.2 and resolve all deprecation warnings.

Or in 3 simple steps:

1. Update your composer.json to `"art4/json-api-client": "^0.10.2"`
2. Make your code deprecation warnings free
3. Upgrade your composer.json to `"art4/json-api-client": "^1.0"` without breaking your app

(Compare the [Symfony upgrade documentation](https://symfony.com/doc/current/setup/upgrade_major.html))

🚀 Usage
-------

[](#rocket-usage)

See the [quickstart guide](docs/helper-parser.md) or the [documentation](docs/README.md).

### Using as parser

[](#using-as-parser)

```
use Art4\JsonApiClient\Exception\InputException;
use Art4\JsonApiClient\Exception\ValidationException;
use Art4\JsonApiClient\Helper\Parser;

// The Response body from a JSON API server
$jsonapiString = '{"meta":{"info":"Testing the JsonApiClient library."}}';

try {
    // Use this if you have a response after calling a JSON API server
    $document = Parser::parseResponseString($jsonapiString);

    // Or use this if you have a request to your JSON API server
    $document = Parser::parseRequestString($jsonapiString);
} catch (InputException $e) {
    // $jsonapiString is not valid JSON
} catch (ValidationException $e) {
    // $jsonapiString is not valid JSON API
}
```

**Note**: Using `Art4\JsonApiClient\Helper\Parser` is just a shortcut for directly using the [Manager](docs/manager.md).

`$document` implements the `Art4\JsonApiClient\Accessable` interface to access the parsed data. It has the methods `has($key)`, `get($key)` and `getKeys()`.

```
// Note that has() and get() have support for dot-notated keys
if ($document->has('meta.info'))
{
    echo $document->get('meta.info'); // "Testing the JsonApiClient library."
}

// you can get all keys as an array
var_dump($document->getKeys());

// array(
//   0 => "meta"
// )
```

### Using as validator

[](#using-as-validator)

JsonApiClient can be used as a validator for JSON API contents:

```
use Art4\JsonApiClient\Helper\Parser;

$wrong_jsonapi = '{"data":{},"meta":{"info":"This is wrong JSON API. `data` has to be `null` or containing at least `type` and `id`."}}';

if ( Parser::isValidResponseString($wrong_jsonapi) ) {
// or Parser::isValidRequestString($wrong_jsonapi)
	echo 'string is valid.';
} else {
	echo 'string is invalid json api!';
}

// echoes 'string is invalid json api!'
```

### Extend the client

[](#extend-the-client)

Need more functionality? Want to directly inject your model? Easily extend JsonApiClient with the [Factory](docs/utils-factory.md).

🔊 Changelog
-----------

[](#loud_sound-changelog)

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

🔧 Contributing
--------------

[](#wrench-contributing)

Please feel free to fork and sending Pull Requests. This project follows [Semantic Versioning 2](http://semver.org) and [PER-CS2.0](https://www.php-fig.org/per/coding-style/).

This projects comes with a `docker-compose.yml` where all tools for development are available.

Run `docker compose build` to build the image. Once you've build it, run `docker compose up -d` to start the container in the background.

Run `docker compose exec -u 1000 php bash` to use the bash inside the running container. There you can use all tools, e.g. composer with `composer --version`

Use `exit` to logout from the container and `docker compose stop` to stop the running container.

All following commands can be run inside the running docker container.

### ✅ Testing

[](#white_check_mark-testing)

Run PHPUnit for all tests:

```
$ composer run phpunit
```

Run PHPStan for static code analysis:

```
$ composer run phpstan
```

Let PHPUnit generate a HTLM code coverage report:

```
$ composer run coverage
```

You can find the code coverage report in `.phpunit.cache/code-coverage/index.html`.

### ✅ REUSE

[](#white_check_mark-reuse)

The [REUSE Helper tool](https://reuse.software/dev/) makes licensing easy for humans and machines alike. It downloads the full license texts, adds copyright and license information to file headers, and contains a linter to identify problems.

Check all files for REUSE spec compliance:

```
composer run reuse-lint
```

Run this command to annotate PHP files in src and tests folders:

```
composer run reuse-annotate
```

❤️ Credits
----------

[](#heart-credits)

- [Artur Weigandt](https://github.com/Art4)
- [All Contributors](../../contributors)

📄 License
---------

[](#page_facing_up-license)

GPL3. Please see [License File](LICENSE) for more information.

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance47

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.2% 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 ~168 days

Recently: every ~419 days

Total

23

Last Release

270d ago

Major Versions

0.x-dev → 1.0.02021-03-05

PHP version history (7 changes)0.1PHP &gt;=5.4

0.8PHP ^5.5 || ^7.0

0.10PHP ^5.6 || ^7.0

1.0.0PHP ^7.4 || ^8.0

1.2.0PHP ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0

1.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

v1.x-devPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad0c0fa748422ad817c4124a06618a1e655995502be8d6f03d699f38c0d56b0?d=identicon)[Art4](/maintainers/Art4)

---

Top Contributors

[![Art4](https://avatars.githubusercontent.com/u/2162994?v=4)](https://github.com/Art4 "Art4 (509 commits)")[![andrzejkupczyk](https://avatars.githubusercontent.com/u/11018286?v=4)](https://github.com/andrzejkupczyk "andrzejkupczyk (1 commits)")[![mukete](https://avatars.githubusercontent.com/u/4340452?v=4)](https://github.com/mukete "mukete (1 commits)")[![nanawel](https://avatars.githubusercontent.com/u/4866761?v=4)](https://github.com/nanawel "nanawel (1 commits)")[![OskarD](https://avatars.githubusercontent.com/u/6658382?v=4)](https://github.com/OskarD "OskarD (1 commits)")

---

Tags

hacktoberfestjson-apijson-api-clientphpjsonapiclientvalidatorparserreaderJSON-API

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cloudcreativity/laravel-json-api

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

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

Simple PHP Parser Utility Library for API Development

2141.0M3](/packages/nathanmac-parser)[alsvanzelf/jsonapi

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

55158.2k6](/packages/alsvanzelf-jsonapi)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.7M4](/packages/cloudcreativity-json-api-testing)[orisai/object-mapper

Raw data mapping to validated objects

1133.6k2](/packages/orisai-object-mapper)

PHPackages © 2026

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