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

ActiveLibrary

focus/json-api
==============

A collection of tools for working with JSON:API data.

2.0.0(2y ago)21MITPHPPHP ^8.2

Since Nov 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/focusphp/json-api)[ Packagist](https://packagist.org/packages/focus/json-api)[ RSS](/packages/focus-json-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (4)Used By (0)

Focus JSON:API
==============

[](#focus-jsonapi)

[![Minimum PHP Version](https://camo.githubusercontent.com/096d54c993c13914eb318211d51dc5c6a0320bf10027d3ed00a1ceb7804dd6ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3838393242462e7376673f7374796c653d666c6174)](https://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/a48c450b72199b661d21bc5baddc2f052e78d3a85400df1925c38c410937dfd0/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6375732f6a736f6e2d6170692e7376673f7374796c653d666c6174)](https://packagist.org/packages/focus/json-api)[![CI Status](https://github.com/focusphp/data/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/focusphp/data/actions)[![Code Coverage](https://camo.githubusercontent.com/2a26f4a4b0c7de22df42ecb1211b573813e66c2612e01289ca5e6e597827f7e4/68747470733a2f2f636f6465636f762e696f2f67682f666f6375737068702f646174612f67726170682f62616467652e7376673f746f6b656e3d58464d5257413730464e)](https://codecov.io/gh/focusphp/data)

A collection of tools for working with [JSON:API](https://jsonapi.org/) data. This package is an extension of [focus/data](https://github.com/focusphp/data).

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

[](#installation)

The best way to install and use this package is with [composer](https://getcomposer.org/):

```
composer require focus/json-api
```

Basic Usage
-----------

[](#basic-usage)

This package provides some structure to reading JSON:API formatted data. Both resource and resource collections are supported.

The typical entry point will be `DocumentData`:

```
use Focus\JsonApi\DocumentData;

$data = DocumentData::fromRequest($request);
```

***Note:** Like [`JsonData`](https://github.com/focusphp/data#json-data), this package supports reading JSON from strings and [PSR-7](https://github.com/focusphp/data#json-data) request and response objects.*

Once the document is created, the primary data can be accessed as a resource:

```
$book = $data->resource();

var_dump($book->attribute(path: 'title'));
var_dump($book->attribute(path: 'subtitle'));
var_dump($book->relation(name: 'author'));
```

Or a collection of resources:

```
$books = $data->collection();

var_dump($books->ids());
```

Or the included resources:

```
$publishers = $data->included(type: 'publisher');

var_dump($publishers->ids());
```

Types
-----

[](#types)

### Identifiers

[](#identifiers)

The `Identifier` object extends [`Data`](https://github.com/focusphp/data) and adds helper methods to read the type and identifier value:

```
$id = $data->id();
$type = $data->type();
```

### Resources

[](#resources)

The `Resource` object extends from `Identifier` and adds helper methods to read attributes and relationships:

```
$id = $data->id();
$topics = $data->attribute(path: 'topics');
$author = $data->relation(name: 'author');
$publishers = $data->relations(name: 'publishers');
```

- The value of `relation()` is an identifier of a to-one relationship. When the relationship is undefined, `null` will be returned. When the relationship is defined as `null`, a blank `Identifier` will be returned.
- The value of `relations()` is an identifier collection of a to-many relationship. When the relationship is undefined, `null` will be returned. When the relationship is defined as `null`, an empty `IdentifierCollection` will be returned.

The return values of `relation()` and `relations()` are structured this way to allow determining when a relationship is not present (undefined) versus being unset (null).

### Identifier Collections

[](#identifier-collections)

The `IdentifierCollection` object represents a collection of `Identifier` objects and adds helper methods to read the identifier values:

```
var_dump($publishers->ids());
```

The collection can also be iterated:

```
foreach ($publishers as $publisher) {
    var_dump($publisher->id());
    var_dump($publisher->type());
}
```

### Resource Collections

[](#resource-collections)

The `ResourceCollection` object represents a collection of `Resource` objects and adds helper methods to read the identifier values:

```
var_dump($publishers->ids());
```

The collection can also be iterated:

```
foreach ($publishers as $publisher) {
    var_dump($publisher->id());
    var_dump($publisher->attribute(path: 'name'));
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

913d ago

Major Versions

1.0.0 → 2.0.02023-11-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30317.2M40](/packages/simplesamlphp-saml2)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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