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

ActiveLibrary[API Development](/categories/api)

zohurul/json-api-parser
=======================

json:api response parser as https://jsonapi.org/

v1.0.1(6y ago)2253[1 issues](https://github.com/zohurul88/json-api-parser/issues)GPL-3.0-or-laterPHPPHP &gt;=7.1.3CI failing

Since Nov 6Pushed 1y ago2 watchersCompare

[ Source](https://github.com/zohurul88/json-api-parser)[ Packagist](https://packagist.org/packages/zohurul/json-api-parser)[ Docs](https://github.com/zohurul88/json-api-parser)[ RSS](/packages/zohurul-json-api-parser/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

{JSON:API} Parser
=================

[](#jsonapi-parser)

[![PHP from Packagist](https://camo.githubusercontent.com/3661ec2e9d05656d81487df1e611d6edbc559282acd1abd3305069edcdc8b957/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a6f687572756c2f6a736f6e2d6170692d706172736572)](https://camo.githubusercontent.com/3661ec2e9d05656d81487df1e611d6edbc559282acd1abd3305069edcdc8b957/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a6f687572756c2f6a736f6e2d6170692d706172736572) [![Packagist](https://camo.githubusercontent.com/1b5e44d17758cfc943fe237886d1dda269b2bf7ea46dbd63382cacab483251b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a6f687572756c2f6a736f6e2d6170692d706172736572)](https://camo.githubusercontent.com/1b5e44d17758cfc943fe237886d1dda269b2bf7ea46dbd63382cacab483251b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a6f687572756c2f6a736f6e2d6170692d706172736572)

A PHP package to parser ***{JSON:API}*** Response parser or you can say deserializer.

💡 Before start please note that this library only work with [{JSON:API}](https://jsonapi.org/) resources, please visit [https://jsonapi.org](https://jsonapi.org/) for more details.

### Installation

[](#installation)

```
composer require zohurul/json-api-parser

```

### Getting Started

[](#getting-started)

You can simply use the ***Parser*** class to parser the the json string.

```
use JsonApiParser/Parser;
$parser =new Parser($jsonString);
```

##### try to parse a json string

[](#try-to-parse-a-json-string)

the ***ParserException*** to catch all exception

```
use JsonApiParser\Parser;
use JsonApiParser\Exceptions\ParserException;

try{
$parser = new Parser($jsonString);
}catch(ParserException $e){
echo $e->getMessage();
}
```

#### a very complex example

[](#a-very-complex-example)

suppose we have receive this json response from our client

```
{
    "jsonapi": {
        "version": "1.0"
    },
    "meta": {
        "total": 6,
        "current": 2
    },
    "links": {
        "self": "http://example.com/articles",
        "next": "http://example.com/articles?page[offset]=2",
        "last": "http://example.com/articles?page[offset]=10"
    },
    "data": [
        {
            "type": "articles",
            "id": "1",
            "attributes": {
                "title": "JSON:API paints my bikeshed!"
            },
            "relationships": {
                "author": {
                    "links": {
                        "self": "http://example.com/articles/1/relationships/author",
                        "related": "http://example.com/articles/1/author"
                    },
                    "data": {
                        "type": "people",
                        "id": "9"
                    }
                },
                "comments": {
                    "links": {
                        "self": "http://example.com/articles/1/relationships/comments",
                        "related": "http://example.com/articles/1/comments"
                    },
                    "data": [
                        {
                            "type": "comments",
                            "id": "5"
                        },
                        {
                            "type": "comments",
                            "id": "12"
                        }
                    ]
                }
            },
            "links": {
                "self": "http://example.com/articles/1"
            }
        },
        {
            "type": "articles",
            "id": "2",
            "attributes": {
                "title": "JSON:API paints my bikeshed 2!"
            },
            "relationships": {
                "author": {
                    "links": {
                        "self": "http://example.com/articles/1/relationships/author",
                        "related": "http://example.com/articles/1/author"
                    },
                    "data": {
                        "type": "people",
                        "id": "19"
                    }
                },
                "comments": {
                    "links": {
                        "self": "http://example.com/articles/1/relationships/comments",
                        "related": "http://example.com/articles/1/comments"
                    },
                    "data": {
                        "type": "comments",
                        "id": "13"
                    }
                }
            },
            "links": {
                "self": "http://example.com/articles/1"
            }
        }
    ],
    "included": [
        {
            "type": "people",
            "id": "9",
            "attributes": {
                "firstName": "Dan",
                "lastName": "Gebhardt",
                "twitter": "dgeb"
            },
            "links": {
                "self": "http://example.com/people/9"
            }
        },
        {
            "type": "people",
            "id": "2",
            "attributes": {
                "firstName": "Dan2",
                "lastName": "Gebhardt2",
                "twitter": "dgeb2"
            },
            "links": {
                "self": "http://example.com/people/2"
            }
        },
        {
            "type": "comments",
            "id": "5",
            "attributes": {
                "body": "First!"
            },
            "relationships": {
                "author": {
                    "data": {
                        "type": "people",
                        "id": "2"
                    }
                }
            },
            "links": {
                "self": "http://example.com/comments/5"
            }
        },
        {
            "type": "comments",
            "id": "12",
            "attributes": {
                "body": "I like XML better"
            },
            "relationships": {
                "author": {
                    "data": {
                        "type": "people",
                        "id": "9"
                    }
                }
            },
            "links": {
                "self": "http://example.com/comments/12"
            }
        },
        {
            "type": "comments",
            "id": "13",
            "attributes": {
                "body": "I like XML better"
            },
            "relationships": {
                "author": {
                    "data": {
                        "type": "people",
                        "id": "9"
                    }
                }
            },
            "links": {
                "self": "http://example.com/comments/12"
            }
        },
        {
            "type": "comments",
            "id": "17",
            "attributes": {
                "body": "I like XML better"
            },
            "relationships": {
                "author": {
                    "data": {
                        "type": "people",
                        "id": "9"
                    }
                }
            },
            "links": {
                "self": "http://example.com/comments/12"
            }
        }
    ]
}
```

And we wanted to print all the information by nested loop

```
use JsonApiParser\Parser;

$parser = new Parser($jsonString);
//To print a version
echo $parser->version();
//Whole meta object
print_r($parser->meta());
//Single meta object
echo $parser->meta()->total;

//To get whole links object
print_r($parser->links());
//To get a single link
echo $parser->links()->self;

//prepare included relational data
$included = $parser->included();
//main data block
$articles = $parser->data();

foreach ($articles as $article) {
    //print the article type
    echo $article->type();
    //print the article id
    echo $article->id();

    //To check if any specific key exist
    var_dump($item->contain('attributes', 'title'));

    //to print an item attribute
    echo $item->attribute()->title;

    //Fetch a relationship object by relationship name
    $comments = $item->relationships("comments");

    //To print all the comments
    foreach ($comments->data() as $comment) {
        //print the id
        echo $comment->id();
        //Fetch the relational data from included
        $commentItem = $comment->comments();

        //print it's attribute
        echo $commentItem->attribute()->body;

        $authors = $commentItem->relationships("author");
        foreach($authors->data() as $author){
            //author id
            echo $author->id();

            //to print the author attribute item
            echo $author->people()->attribute()->twitter;
        }

     }

}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

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

Total

2

Last Release

2383d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a47cfc8b9bd894e7abf025123ea86bb7c2c3b4c0151e251c8985b141c42420d8?d=identicon)[zohurul](/maintainers/zohurul)

---

Top Contributors

[![zohurul](https://avatars.githubusercontent.com/u/6093194?v=4)](https://github.com/zohurul "zohurul (11 commits)")

---

Tags

jsonapiclientvalidatorparserreaderJSON-API

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[art4/json-api-client

JSON API client

139791.3k7](/packages/art4-json-api-client)[cloudcreativity/laravel-json-api

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

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

Simple PHP Parser Utility Library for API Development

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

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

54150.0k5](/packages/alsvanzelf-jsonapi)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.6M3](/packages/cloudcreativity-json-api-testing)[orisai/object-mapper

Raw data mapping to validated objects

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

PHPackages © 2026

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