jacobfennik / json-api-normalizer
Simple package to handle response from JSON:API
v0.1-beta.1
2018-12-12 01:10 UTC
Requires
- illuminate/support: ^5.7
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2025-06-12 14:49:38 UTC
README
Utility to normalize and build JSON:API response data.
Install
$ composer require jacobfennik/json-api-normalizer
Example
Building with the normalizer
<?php use JacobFennik\JsonApiNormalizer\Normalizer; $apiResponse = ' { "data": [{ "type": "articles", "id": "1", "attributes": { "title": "JSON:API paints my bikeshed!" }, "relationships": { "author": { "data": { "type": "people", "id": "9" } }, } }], "included": [{ "type": "people", "id": "9", "attributes": { "firstName": "Dan", "lastName": "Gebhardt", "twitter": "dgeb" }, }] } '; $normalizer = new Normalizer($apiResponse); $built = $normalizer->build();
Accessing built data
<?php $normalizer = new Normalizer($apiResponse); $article = $normalizer->build(1); // Build object with id '1' $title = $article->title; $authorFirstName = $article->author->firstName;